Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- output:
- changed from thread: 99
- thread: 0x7f9c3e91e6fc
- thread: 0x7f9c3e91f73c
- thread: 0x7f9c3e91f73c
- 10
- #include <sys/wait.h>
- #include <stdio.h>
- int __thread lala;
- static pthread_cond_t wc = PTHREAD_COND_INITIALIZER;
- static pthread_mutex_t wt = PTHREAD_MUTEX_INITIALIZER;
- void *thread(void *n)
- {
- setgid(99);
- pthread_cond_wait(&wc, &wt);
- printf ("thread: %p\n", &lala);
- }
- int main()
- {
- pid_t pid;
- lala = 10;
- pthread_t t;
- pthread_create(&t, NULL, &thread, NULL);
- sleep (10);
- printf ("changed from thread: %lu\n", getgid());
- pthread_cond_broadcast(&wc);
- pthread_join(t, NULL);
- if ((pid = fork()) > 0) {
- printf ("thread: %p\n", &lala);
- wait(NULL);
- } else {
- printf ("thread: %p\n", &lala);
- printf ("%d\n", lala);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement