Debian Codegraph @

gcc/testsuite/c-c++-common/tsan/atomic_stack.c

raw
1 /* { dg-shouldfail "tsan" } */
2 /* { dg-additional-options "-ldl" } */
3
4 #include <pthread.h>
5 #include "tsan_barrier.h"
6
7 static pthread_barrier_t barrier;
8 int Global;
9
10 void *Thread1(void *x) {
11 barrier_wait(&barrier);
12 __atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED);
13 return NULL;
14 }
15
16 void *Thread2(void *x) {
17 Global++;
18 barrier_wait(&barrier);
19 return NULL;
20 }
21
22 int main() {
23 barrier_init(&barrier, 2);
24 pthread_t t[2];
25 pthread_create(&t[0], NULL, Thread1, NULL);
26 pthread_create(&t[1], NULL, Thread2, NULL);
27 pthread_join(t[0], NULL);
28 pthread_join(t[1], NULL);
29 return 0;
30 }
31
32 /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */
33 /* { dg-output " Atomic write of size 4.*" } */
34 /* { dg-output " #0 Thread1.*" } */