blob: d28b5b962c750082bb8a0230b617d7a8594c4d4b [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2#include <pthread.h>
3#include <unistd.h>
4
5int Global;
6
7void *Thread1(void *x) {
8 sleep(1);
9 __atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED);
10 return NULL;
11}
12
13void *Thread2(void *x) {
14 Global++;
15 return NULL;
16}
17
18int main() {
19 pthread_t t[2];
20 pthread_create(&t[0], NULL, Thread1, NULL);
21 pthread_create(&t[1], NULL, Thread2, NULL);
22 pthread_join(t[0], NULL);
23 pthread_join(t[1], NULL);
24}
25
26// CHECK: WARNING: ThreadSanitizer: data race
27// CHECK: Atomic write of size 4
28// CHECK: #0 __tsan_atomic32_fetch_add
29// CHECK: #1 Thread1