123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include<stdio.h>
- #include<string.h>
- #include<pthread.h>
- #include<stdlib.h>
- #include<unistd.h>
- pthread_t tid[2];
- void* doSomeThing(void *arg)
- {
- unsigned long i = 0;
- pthread_t id = pthread_self();
- if(pthread_equal(id,tid[0]))
- {
- printf("\n First thread processing\n");
- }
- else
- {
- printf("\n Second thread processing\n");
- }
- for(i=0; i<(0xFFFFFFFF);i++);
- return NULL;
- }
- int main(void)
- {
- int i = 0;
- int err;
- while(i < 2)
- {
- err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
- if (err != 0)
- printf("\ncan't create thread :[%s]", strerror(err));
- else
- printf("\n Thread created successfully\n");
- i++;
- }
-
- //this belongs all to the new feature of the app
- signal(SIGINT, sighandler);
- while(1) {
- printf("Going to sleep for a second...\n");
- sleep(1);
- }
- sleep(5);
- return 0;
- }
- //this also belongs to the new signal feature
- void sighandler(int signum) {
- printf("Caught signal %d, coming out...\n", signum);
- exit(1);
- }
|