26 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s2#include "test.h"3 4const int kThreads = 16;5const int kIters = 1000;6 7volatile int X = 0;8 9void *thr(void *arg) {10 for (int i = 0; i < kIters; i++)11 X++;12 return 0;13}14 15int main() {16 pthread_t th[kThreads];17 for (int i = 0; i < kThreads; i++)18 pthread_create(&th[i], 0, thr, 0);19 for (int i = 0; i < kThreads; i++)20 pthread_join(th[i], 0);21 fprintf(stderr, "DONE\n");22}23 24// CHECK: ThreadSanitizer: data race25// CHECK: DONE26