| 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
|---|---|
| 2 | #include "test.h" |
| 3 | #include <pthread.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stddef.h> |
| 6 | |
| 7 | void *Thread(void *a) { |
| 8 | ((int*)a)[0]++; |
| 9 | barrier_wait(barrier: &barrier); |
| 10 | return NULL; |
| 11 | } |
| 12 | |
| 13 | int main() { |
| 14 | barrier_init(barrier: &barrier, count: 2); |
| 15 | int *p = new int(42); |
| 16 | pthread_t t; |
| 17 | pthread_create(newthread: &t, NULL, start_routine: Thread, arg: p); |
| 18 | barrier_wait(barrier: &barrier); |
| 19 | p[0]++; |
| 20 | pthread_join(th: t, NULL); |
| 21 | delete p; |
| 22 | } |
| 23 | |
| 24 | // CHECK: WARNING: ThreadSanitizer: data race |
| 25 |
