brintos

brintos / llvm-project-archived public Read only

0
0
Text · 630 B · f38a98c Raw
30 lines · c
1// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s2 3#include "test.h"4 5int *mem;6 7void *Thread(void *x) {8  mem[0] = 42;9  barrier_wait(&barrier);10  return NULL;11}12 13int main() {14  barrier_init(&barrier, 2);15  mem = (int*)malloc(100);16  pthread_t t;17  pthread_create(&t, 0, Thread, 0);18  barrier_wait(&barrier);19  free(mem);20  pthread_join(t, NULL);21  return 0;22}23 24// CHECK: WARNING: ThreadSanitizer: data race25// CHECK:   Write of size 8 at {{.*}} by main thread{{.*}}:26// CHECK:     #0 free27// CHECK:     #{{(1|2)}} main28// CHECK:   Previous write of size 4 at {{.*}} by thread T1{{.*}}:29// CHECK:     #0 Thread30