| 1 | #include <pthread.h> |
| 2 | #include <signal.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | static int do_test (void); |
| 9 | |
| 10 | #define TEST_FUNCTION do_test () |
| 11 | #include "../test-skeleton.c" |
| 12 | |
| 13 | static pthread_barrier_t b; |
| 14 | |
| 15 | |
| 16 | static void * |
| 17 | tf2 (void *arg) |
| 18 | { |
| 19 | while (1) |
| 20 | sleep (seconds: 100); |
| 21 | |
| 22 | /* NOTREACHED */ |
| 23 | return NULL; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | static void * |
| 28 | tf (void *arg) |
| 29 | { |
| 30 | pthread_t th; |
| 31 | |
| 32 | int e = pthread_barrier_wait (barrier: &b); |
| 33 | if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) |
| 34 | { |
| 35 | puts (s: "barrier_wait failed" ); |
| 36 | exit (1); |
| 37 | } |
| 38 | |
| 39 | e = pthread_create (newthread: &th, NULL, start_routine: tf2, NULL); |
| 40 | if (e != 0) |
| 41 | { |
| 42 | printf (format: "create failed: %s\n" , strerror (errnum: e)); |
| 43 | exit (1); |
| 44 | } |
| 45 | |
| 46 | /* Terminate only this thread. */ |
| 47 | return NULL; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | static int |
| 52 | do_test (void) |
| 53 | { |
| 54 | pthread_t th; |
| 55 | |
| 56 | if (pthread_barrier_init (barrier: &b, NULL, count: 2) != 0) |
| 57 | { |
| 58 | puts (s: "barrier_init failed" ); |
| 59 | exit (1); |
| 60 | } |
| 61 | |
| 62 | int e = pthread_create (newthread: &th, NULL, start_routine: tf, NULL); |
| 63 | if (e != 0) |
| 64 | { |
| 65 | printf (format: "create failed: %s\n" , strerror (errnum: e)); |
| 66 | exit (1); |
| 67 | } |
| 68 | |
| 69 | e = pthread_barrier_wait (barrier: &b); |
| 70 | if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) |
| 71 | { |
| 72 | puts (s: "barrier_wait failed" ); |
| 73 | exit (1); |
| 74 | } |
| 75 | |
| 76 | delayed_exit (seconds: 3); |
| 77 | |
| 78 | /* Terminate only this thread. */ |
| 79 | pthread_exit (NULL); |
| 80 | |
| 81 | /* NOTREACHED */ |
| 82 | return 1; |
| 83 | } |
| 84 | |