Merge from trunk
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / sleep_sync.c
blob44d44554c2ec74eb4abc5d026164c2cb424dfa87
1 /* { dg-shouldfail "tsan" } */
3 #include <pthread.h>
4 #include <unistd.h>
6 int X = 0;
8 void MySleep() {
9 sleep(1);
12 void *Thread(void *p) {
13 MySleep(); // Assume the main thread has done the write.
14 X = 42;
15 return 0;
18 int main() {
19 pthread_t t;
20 pthread_create(&t, 0, Thread, 0);
21 X = 43;
22 pthread_join(t, 0);
23 return 0;
26 /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r).*} */
27 /* { dg-output " As if synchronized via sleep:(\n|\r\n|\r)} */
28 /* { dg-output " #0 sleep.*"*} */
29 /* { dg-output " #1 MySleep.*"*} */
30 /* { dg-output " #2 Thread.*"*} */