]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s |
2 | // RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s | |
3 | #include "test.h" | |
1a4d82fc JJ |
4 | |
5 | volatile int X; | |
6 | volatile int N; | |
7 | void (*volatile F)(); | |
8 | ||
9 | static void foo() { | |
10 | if (--N == 0) | |
11 | X = 42; | |
12 | else | |
13 | F(); | |
14 | } | |
15 | ||
16 | void *Thread(void *p) { | |
17 | #ifdef ORDER1 | |
92a42be0 | 18 | barrier_wait(&barrier); |
1a4d82fc JJ |
19 | #endif |
20 | F(); | |
92a42be0 SL |
21 | #ifdef ORDER2 |
22 | barrier_wait(&barrier); | |
23 | #endif | |
1a4d82fc JJ |
24 | return 0; |
25 | } | |
26 | ||
2c00a5a8 XL |
27 | static size_t RoundUp(size_t n, size_t to) { |
28 | return ((n + to - 1) / to) * to; | |
29 | } | |
30 | ||
1a4d82fc | 31 | int main() { |
92a42be0 | 32 | barrier_init(&barrier, 2); |
1a4d82fc JJ |
33 | N = 50000; |
34 | F = foo; | |
35 | pthread_t t; | |
36 | pthread_attr_t a; | |
37 | pthread_attr_init(&a); | |
2c00a5a8 XL |
38 | size_t stack_size = N * 256 + (1 << 20); |
39 | stack_size = RoundUp(stack_size, 0x10000); // round the stack size to 64k | |
40 | int ret = pthread_attr_setstacksize(&a, stack_size); | |
41 | if (ret) abort(); | |
1a4d82fc JJ |
42 | pthread_create(&t, &a, Thread, 0); |
43 | #ifdef ORDER2 | |
92a42be0 | 44 | barrier_wait(&barrier); |
1a4d82fc JJ |
45 | #endif |
46 | X = 43; | |
92a42be0 SL |
47 | #ifdef ORDER1 |
48 | barrier_wait(&barrier); | |
49 | #endif | |
50 | ||
1a4d82fc JJ |
51 | pthread_join(t, 0); |
52 | } | |
53 | ||
54 | // CHECK: WARNING: ThreadSanitizer: data race | |
55 | // CHECK: #100 foo | |
56 | // We must output suffucuently large stack (at least 100 frames) | |
57 |