Debian Codegraph @

gcc/testsuite/c-c++-common/tsan/mutexset1.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 pthread_mutex_t mtx;
10
11 void *Thread1(void *x) {
12 barrier_wait(&barrier);
13 pthread_mutex_lock(&mtx);
14 Global++;
15 pthread_mutex_unlock(&mtx);
16 return NULL;
17 }
18
19 void *Thread2(void *x) {
20 Global--;
21 barrier_wait(&barrier);
22 return NULL;/* { dg-output ".*" } */
23
24 }
25
26 int main() {
27 barrier_init(&barrier, 2);
28 pthread_mutex_init(&mtx, 0);
29 pthread_t t[2];
30 pthread_create(&t[0], NULL, Thread1, NULL);
31 pthread_create(&t[1], NULL, Thread2, NULL);
32 pthread_join(t[0], NULL);
33 pthread_join(t[1], NULL);
34 pthread_mutex_destroy(&mtx);
35 return 0;
36 }
37
38 /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */
39 /* { dg-output " Read of size 4 at 0x\[0-9a-f\]+ by thread T1 \\(mutexes: write M\[0-9\]\\):.*" } */
40 /* { dg-output " Previous write of size 4 at 0x\[0-9a-f\]+ by thread T2:.*" } */
41 /* { dg-output " Mutex M\[0-9\] \\(0x.*\\) created at:.*" } */
42 /* { dg-output " #0 pthread_mutex_init.*" } */
43 /* { dg-output " #1 main (.*mutexset1.c|\\?{2}):\[0-9]+.*" } */