Update ChangeLog and version files for release
[official-gcc.git] / gcc / testsuite / c-c++-common / tsan / fd_pipe_race.c
blobe2176da4b628dee2704b07239b49a8d9453a8cec
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 fds[2];
11 void *Thread1(void *x) {
12 write(fds[1], "a", 1);
13 barrier_wait(&barrier);
14 return NULL;
17 void *Thread2(void *x) {
18 barrier_wait(&barrier);
19 close(fds[0]);
20 close(fds[1]);
21 return NULL;
24 int main() {
25 barrier_init(&barrier, 2);
26 pipe(fds);
27 pthread_t t[2];
28 pthread_create(&t[0], NULL, Thread1, NULL);
29 pthread_create(&t[1], NULL, Thread2, NULL);
30 pthread_join(t[0], NULL);
31 pthread_join(t[1], NULL);
32 return 0;
35 /* { dg-output "WARNING: ThreadSanitizer: data race.*\n" } */
36 /* { dg-output " Write of size 8.*\n" } */
37 /* { dg-output " #0 close.*\n" } */
38 /* { dg-output " #1 Thread2.*\n" } */
39 /* { dg-output " Previous read of size 8.*\n" } */
40 /* { dg-output " #0 write.*\n" } */
41 /* { dg-output " #1 Thread1.*\n" } */