blob: 88c4ed4aa3980be7d5414ec09341447dac8a6c8d [file] [log] [blame]
Dmitry Vyukov233f4012014-05-30 14:08:51 +00001// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
Dmitry Vyukov0ef99e22012-12-07 16:22:54 +00002#include <pthread.h>
3#include <stdio.h>
4#include <unistd.h>
5
6int fds[2];
7
8void *Thread1(void *x) {
9 write(fds[1], "a", 1);
10 return NULL;
11}
12
13void *Thread2(void *x) {
14 sleep(1);
15 close(fds[0]);
16 close(fds[1]);
17 return NULL;
18}
19
20int main() {
21 pipe(fds);
22 pthread_t t[2];
23 pthread_create(&t[0], NULL, Thread1, NULL);
24 pthread_create(&t[1], NULL, Thread2, NULL);
25 pthread_join(t[0], NULL);
26 pthread_join(t[1], NULL);
27}
28
29// CHECK: WARNING: ThreadSanitizer: data race
Dmitry Vyukov04580512012-12-07 18:30:40 +000030// CHECK: Write of size 8
Dmitry Vyukov0ef99e22012-12-07 16:22:54 +000031// CHECK: #0 close
32// CHECK: #1 Thread2
Dmitry Vyukov04580512012-12-07 18:30:40 +000033// CHECK: Previous read of size 8
Dmitry Vyukov0ef99e22012-12-07 16:22:54 +000034// CHECK: #0 write
35// CHECK: #1 Thread1
36
37