brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 5b4c7b9 Raw
42 lines · cpp
1// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \2// RUN:   %deflake %run %t | FileCheck %s3#include "test.h"4 5int Global;6__thread int huge[1024*1024];7 8void *Thread1(void *x) {9  barrier_wait(&barrier);10  Global++;11  return NULL;12}13 14void *Thread2(void *x) {15  pthread_mutex_t *mtx = new pthread_mutex_t;16  pthread_mutex_init(mtx, 0);17  pthread_mutex_lock(mtx);18  Global--;19  pthread_mutex_unlock(mtx);20  pthread_mutex_destroy(mtx);21  delete mtx;22  barrier_wait(&barrier);23  return NULL;24}25 26int main() {27  barrier_init(&barrier, 2);28  pthread_t t[2];29  pthread_create(&t[0], NULL, Thread1, NULL);30  pthread_create(&t[1], NULL, Thread2, NULL);31  pthread_join(t[0], NULL);32  pthread_join(t[1], NULL);33}34 35// CHECK: WARNING: ThreadSanitizer: data race36// CHECK: Write of size 4 at {{.*}} by thread T1:37// CHECK: Previous write of size 4 at {{.*}} by thread T238// CHECK:                                      (mutexes: write [[M1:M[0-9]+]]):39// CHECK: Mutex [[M1]] (0x{{.*}}) created at:40// CHECK:   #0 pthread_mutex_init41// CHECK:   #1 Thread242