]>
Commit | Line | Data |
---|---|---|
85826504 MO |
1 | /* { dg-shouldfail "tsan" } */ |
2 | ||
3 | #include <pthread.h> | |
4 | #include <stdio.h> | |
5 | #include <unistd.h> | |
6 | ||
7 | int Global; | |
8 | pthread_mutex_t mtx; | |
9 | ||
10 | void *Thread1(void *x) { | |
11 | sleep(1); | |
12 | pthread_mutex_lock(&mtx); | |
13 | Global++; | |
14 | pthread_mutex_unlock(&mtx); | |
15 | return NULL; | |
16 | } | |
17 | ||
18 | void *Thread2(void *x) { | |
19 | Global--; | |
20 | return NULL;/* { dg-output ".*" } */ | |
21 | ||
22 | } | |
23 | ||
24 | int main() { | |
25 | pthread_mutex_init(&mtx, 0); | |
26 | pthread_t t[2]; | |
27 | pthread_create(&t[0], NULL, Thread1, NULL); | |
28 | pthread_create(&t[1], NULL, Thread2, NULL); | |
29 | pthread_join(t[0], NULL); | |
30 | pthread_join(t[1], NULL); | |
31 | pthread_mutex_destroy(&mtx); | |
32 | return 0; | |
33 | } | |
34 | ||
35 | /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */ | |
36 | /* { dg-output " Read of size 4 at 0x\[0-9a-f\]+ by thread T1 \\(mutexes: write M\[0-9\]\\):.*" } */ | |
37 | /* { dg-output " Previous write of size 4 at 0x\[0-9a-f\]+ by thread T2:.*" } */ | |
dee5ea7a | 38 | /* { dg-output " Mutex M\[0-9\] \\(0x.*\\) created at:.*" } */ |
85826504 MO |
39 | /* { dg-output " #0 pthread_mutex_init.*" } */ |
40 | /* { dg-output " #1 main (.*mutexset1.c|\\?{2}):\[0-9]+.*" } */ |