libA.c 769 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. sleep(5);
  36. return 0;
  37. }