[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / race_with_finished_thread.cc
blobb3f9b706651fc209b3b56272b586d9d53c8308b8
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stddef.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
8 // Ensure that we can restore a stack of a finished thread.
10 int g_data;
12 void __attribute__((noinline)) foobar(int *p) {
13 *p = 42;
16 void *Thread1(void *x) {
17 foobar(&g_data);
18 return NULL;
21 void *Thread2(void *x) {
22 sleep(1);
23 g_data = 43;
24 return NULL;
27 int main() {
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 return 0;
36 // CHECK: WARNING: ThreadSanitizer: data race
37 // CHECK: Write of size 4 at {{.*}} by thread T2:
38 // CHECK: Previous write of size 4 at {{.*}} by thread T1:
39 // CHECK: #0 foobar
40 // CHECK: #1 Thread1
41 // CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
42 // CHECK: #0 pthread_create
43 // CHECK: #1 main