llvm-project
25 строк · 540.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"3
4int Global;5pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER;6
7void *Thread(void *x) {8AnnotateIgnoreSyncBegin(0, 0);9pthread_mutex_lock(&Mutex);10Global++;11pthread_mutex_unlock(&Mutex);12AnnotateIgnoreSyncEnd(0, 0);13return 0;14}
15
16int main() {17pthread_t t;18pthread_create(&t, 0, Thread, 0);19pthread_mutex_lock(&Mutex);20Global++;21pthread_mutex_unlock(&Mutex);22pthread_join(t, 0);23}
24
25// CHECK: WARNING: ThreadSanitizer: data race
26
27