Advertisement
alexarcan

os

Dec 9th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4.  
  5. void *thread_code(void *arg)
  6. {
  7. int i;
  8.  
  9. for(i=0; i<1000; i++)
  10. printf("%s", (char *)arg);
  11. printf("\n");
  12.  
  13. return (void *)( *((char *)arg) - 'A' + 1);
  14. }
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18. pthread_t th1, th2;
  19. void *ret1, *ret2;
  20.  
  21. pthread_create( &th1, NULL, thread_code, (void*) "A");
  22. pthread_create( &th2, NULL, thread_code, (void*) "B");
  23.  
  24. printf("Threads created.\n");
  25.  
  26. pthread_join(th1, &ret1);
  27. pthread_join(th2, &ret2);
  28.  
  29. printf("Thread 1 ends returning: %d.\n", (int)ret1);
  30. printf("Thread 2 ends returning: %d.\n", (int)ret2);
  31. exit(0);
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement