llvm-project
36 строк · 883.0 Байт
1// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
2// RUN: %deflake %run %t | \
3// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
4#include "test.h"5
6void *Thread2(void *a) {7barrier_wait(&barrier);8*(int*)a = 43;9return 0;10}
11
12void *Thread(void *a) {13static __thread int Var = 42;14pthread_t t;15pthread_create(&t, 0, Thread2, &Var);16Var = 42;17barrier_wait(&barrier);18pthread_join(t, 0);19return 0;20}
21
22int main() {23barrier_init(&barrier, 2);24pthread_t t;25pthread_create(&t, 0, Thread, 0);26pthread_join(t, 0);27fprintf(stderr, "DONE\n");28return 0;29}
30
31// CHECK: WARNING: ThreadSanitizer: data race
32// CHECK-Linux: Location is TLS of thread T1.
33// CHECK-FreeBSD: Location is TLS of thread T1.
34// CHECK-NetBSD: Location is TLS of thread T1.
35// CHECK-Darwin: Location is heap block of size 4
36// CHECK: DONE
37