PR target/83368
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / race_on_barrier2.c
blobb01a5cc21a27010f0ca78ede051b1683f5746c11
1 /* { dg-shouldfail "tsan" } */
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stddef.h>
6 #include <unistd.h>
8 pthread_barrier_t B;
9 int Global;
11 void *Thread1(void *x) {
12 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
13 pthread_barrier_destroy(&B);
14 return NULL;
17 void *Thread2(void *x) {
18 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD)
19 pthread_barrier_destroy(&B);
20 return NULL;
23 int main() {
24 pthread_barrier_init(&B, 0, 2);
25 pthread_t t;
26 pthread_create(&t, NULL, Thread1, NULL);
27 Thread2(0);
28 pthread_join(t, NULL);
29 return 0;
32 /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */