Advertisement
Guest User

Untitled

a guest
Oct 27th, 2011
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <pthread.h>
  4.  
  5. void *threadMessage( void *ptr );
  6.  
  7. main()
  8. {
  9. pthread_t thread1, thread2;
  10. char *message1 = "Thread 1 says hi !";
  11. char *message2 = "Thread 2 says hi !";
  12. int retStat1, retStat2;
  13.  
  14. retStat1 = pthread_create( &thread1, NULL, threadMessage, (void *) message1);
  15.  
  16. retStat2 = pthread_create( &thread2, NULL, threadMessage, (void *) message2);
  17. pthread_join( thread1, NULL);
  18. pthread_join( thread2, NULL);
  19.  
  20. printf("Thread 1 returns: %d\n",retStat1);
  21. printf("Thread 2 returns: %d\n",retStat2);
  22.  
  23. exit(0);
  24. }
  25.  
  26. void *threadMessage( void *ptr )
  27. {
  28.  
  29. char *message = (char *) ptr;
  30. printf("%s \n", message);
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement