Advertisement
marmolak

Untitled

Sep 19th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. output:
  2. changed from thread: 99
  3. thread: 0x7f9c3e91e6fc
  4. thread: 0x7f9c3e91f73c
  5. thread: 0x7f9c3e91f73c
  6. 10
  7.  
  8.  
  9. #include <sys/wait.h>
  10. #include <stdio.h>
  11.  
  12. int __thread lala;
  13.  
  14. static pthread_cond_t wc = PTHREAD_COND_INITIALIZER;
  15. static pthread_mutex_t wt = PTHREAD_MUTEX_INITIALIZER;
  16.  
  17. void *thread(void *n)
  18. {
  19. setgid(99);
  20. pthread_cond_wait(&wc, &wt);
  21. printf ("thread: %p\n", &lala);
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27. pid_t pid;
  28. lala = 10;
  29.  
  30. pthread_t t;
  31. pthread_create(&t, NULL, &thread, NULL);
  32.  
  33. sleep (10);
  34.  
  35. printf ("changed from thread: %lu\n", getgid());
  36. pthread_cond_broadcast(&wc);
  37. pthread_join(t, NULL);
  38.  
  39. if ((pid = fork()) > 0) {
  40. printf ("thread: %p\n", &lala);
  41. wait(NULL);
  42. } else {
  43. printf ("thread: %p\n", &lala);
  44. printf ("%d\n", lala);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement