Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ysionneau@xxxxx ~]$ cat puts.c
- #include <pthread.h>
- #include <stdio.h>
-
- static pthread_barrier_t bar;
-
- static void *t1(void *arg)
- {
- printf("Thread started.\n");
- pthread_barrier_wait(&bar);
- pthread_barrier_wait(&bar);
- puts("we try to write!\n");
- }
-
- int main(void)
- {
- pthread_t thread;
-
- printf("Starting pthread...\n");
-
- pthread_barrier_init(&bar, NULL, 2);
- pthread_create(&thread, NULL, &t1, NULL);
-
- pthread_barrier_wait(&bar);
- printf("Canceling our thread\n");
- pthread_cancel(thread);
- pthread_barrier_wait(&bar);
-
- pthread_join(thread, NULL);
-
- puts("we also try to write\n");
-
- return 0;
- }
- [ysionneau@xxxxx ~]$ gcc puts.c -o puts -pthread
Add Comment
Please, Sign In to add comment