Merge from trunk
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / mutexset1.c
blob7c32a8524b44ceefd609ac868bf7ab2c038f78a4
1 /* { dg-shouldfail "tsan" } */
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <unistd.h>
7 int Global;
8 pthread_mutex_t mtx;
10 void *Thread1(void *x) {
11 sleep(1);
12 pthread_mutex_lock(&mtx);
13 Global++;
14 pthread_mutex_unlock(&mtx);
15 return NULL;
18 void *Thread2(void *x) {
19 Global--;
20 return NULL;/* { dg-output ".*" } */
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;
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:.*" } */
38 /* { dg-output " Mutex M\[0-9\] created at:.*" } */
39 /* { dg-output " #0 pthread_mutex_init.*" } */
40 /* { dg-output " #1 main (.*mutexset1.c|\\?{2}):\[0-9]+.*" } */