1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
8 static int malloc_count
;
12 void __tsan_malloc_hook(void *ptr
, size_t size
) {
15 __sync_fetch_and_add(&malloc_count
, 1);
18 void __tsan_free_hook(void *ptr
) {
20 __sync_fetch_and_add(&free_count
, 1);
24 void *Thread1(void *x
) {
29 void *Thread2(void *x
) {
38 pthread_create(&t
[0], 0, Thread1
, x
);
39 pthread_create(&t
[1], 0, Thread2
, x
);
40 pthread_join(t
[0], 0);
41 pthread_join(t
[1], 0);
43 if (malloc_count
== 0 || free_count
== 0) {
44 fprintf(stderr
, "FAILED %d %d\n", malloc_count
, free_count
);
47 fprintf(stderr
, "DONE\n");
50 // CHECK: WARNING: ThreadSanitizer: data race