libA.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<pthread.h>
  4. #include<stdlib.h>
  5. #include<unistd.h>
  6. pthread_t tid[2];
  7. void* doSomeThing(void *arg)
  8. {
  9. unsigned long i = 0;
  10. pthread_t id = pthread_self();
  11. if(pthread_equal(id,tid[0]))
  12. {
  13. printf("\n First thread processing\n");
  14. }
  15. else
  16. {
  17. printf("\n Second thread processing\n");
  18. }
  19. for(i=0; i<(0xFFFFFFFF);i++);
  20. return NULL;
  21. }
  22. int main(void)
  23. {
  24. int i = 0;
  25. int err;
  26. while(i < 2)
  27. {
  28. err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
  29. if (err != 0)
  30. printf("\ncan't create thread :[%s]", strerror(err));
  31. else
  32. printf("\n Thread created successfully\n");
  33. i++;
  34. }
  35. //this belongs all to the new feature of the app
  36. signal(SIGINT, sighandler);
  37. while(1) {
  38. printf("Going to sleep for a second...\n");
  39. sleep(1);
  40. }
  41. sleep(5);
  42. return 0;
  43. }
  44. //this also belongs to the new signal feature
  45. void sighandler(int signum) {
  46. printf("Caught signal %d, coming out...\n", signum);
  47. exit(1);
  48. }