Update ChangeLog and version files for release
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / sleep_sync.c
blobc681dcef1bfd41612127674350992bd671ec2294
1 /* { dg-shouldfail "tsan" } */
2 /* { dg-additional-options "-ldl" } */
4 #include <pthread.h>
5 #include <unistd.h>
6 #include "tsan_barrier.h"
8 static pthread_barrier_t barrier;
9 int X = 0;
11 void MySleep() {
12 sleep(1);
15 void *Thread(void *p) {
16 barrier_wait(&barrier);
17 MySleep(); // Assume the main thread has done the write.
18 X = 42;
19 return 0;
22 int main() {
23 barrier_init(&barrier, 2);
24 pthread_t t;
25 pthread_create(&t, 0, Thread, 0);
26 X = 43;
27 barrier_wait(&barrier);
28 pthread_join(t, 0);
29 return 0;
32 /* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r).*} */
33 /* { dg-output " As if synchronized via sleep:(\n|\r\n|\r)} */
34 /* { dg-output " #0 sleep.*"*} */
35 /* { dg-output " #1 MySleep.*"*} */
36 /* { dg-output " #2 Thread.*"*} */