2 /* This is the most trivial test I could think of that involves
3 barriers. If H fails to notice the pthread_barrier_wait call then
4 it will report a race. Correct behaviour is not to report a race
15 pthread_barrier_t bar
;
17 void* child_fn ( void* arg
)
19 long r
, n
= (long)arg
;
23 r
= pthread_barrier_wait(&bar
);
24 assert(r
== 0 || r
== PTHREAD_BARRIER_SERIAL_THREAD
);
28 sleep(1); /* ensure both threads get to this point before
40 r
= pthread_barrier_init(&bar
, NULL
, NTHR
);
43 for (i
= 0; i
< NTHR
; i
++) {
44 r
= pthread_create(&thr
[i
], NULL
, child_fn
, (void*)i
);
48 for (i
= 0; i
< NTHR
; i
++) {
49 r
= pthread_join(thr
[i
], NULL
);
53 r
= pthread_barrier_destroy(&bar
); assert(!r
);
55 printf("x = %d\n", x
);