1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include <pthread.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6struct P {
7 int x;
8 int y;
9};
10
11int Helper() {
12 try {
13 static int i = []() {
14 throw P{};
15 return 1;
16 }();
17 return i;
18 } catch (P) {
19 return 0;
20 }
21}
22
23void *Thread(void *x) {
24 for (int i = 0; i < 1000; ++i) {
25 Helper();
26 }
27 return 0;
28}
29
30int main() {
31 pthread_t t[2];
32 pthread_create(newthread: &t[0], attr: 0, start_routine: Thread, arg: 0);
33 pthread_create(newthread: &t[1], attr: 0, start_routine: Thread, arg: 0);
34 pthread_join(th: t[0], thread_return: 0);
35 pthread_join(th: t[1], thread_return: 0);
36 fprintf(stderr, format: "PASS\n");
37}
38
39// CHECK-NOT: WARNING: ThreadSanitizer: data race
40

source code of compiler-rt/test/tsan/static_init7.cpp