1 | // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
2 | |
3 | // on_exit() is not available on Darwin. |
4 | // UNSUPPORTED: darwin |
5 | |
6 | #include "test.h" |
7 | |
8 | volatile long global; |
9 | |
10 | void *thread(void *x) { |
11 | global++; |
12 | barrier_wait(barrier: &barrier); |
13 | return nullptr; |
14 | } |
15 | |
16 | void on_exit_callback(int status, void *arg) { |
17 | fprintf(stderr, format: "on_exit_callback(%d, %lu)\n" , status, (long)arg); |
18 | global++; |
19 | } |
20 | |
21 | int main() { |
22 | on_exit(func: on_exit_callback, arg: (void *)42l); |
23 | barrier_init(barrier: &barrier, count: 2); |
24 | pthread_t th; |
25 | pthread_create(newthread: &th, attr: nullptr, start_routine: thread, arg: nullptr); |
26 | pthread_detach(th: th); |
27 | barrier_wait(barrier: &barrier); |
28 | return 2; |
29 | } |
30 | |
31 | // CHECK: on_exit_callback(2, 42) |
32 | // CHECK: WARNING: ThreadSanitizer: data race |
33 | // CHECK: Write of size 8 |
34 | // CHECK: #0 on_exit_callback |
35 | // CHECK: #1 on_exit_callback_installed_at |
36 | // CHECK: #2 main |
37 | |