1// RUN: %clangxx_tsan %s -o %t -framework Foundation -std=c++11
2// RUN: %run %t 2>&1 | FileCheck %s
3
4#import <Foundation/Foundation.h>
5
6#import <iostream>
7#import <thread>
8
9long my_global;
10std::once_flag once_token;
11
12void thread_func() {
13 std::call_once(once_token, [] {
14 my_global = 17;
15 });
16
17 long val = my_global;
18 fprintf(stderr, "my_global = %ld\n", val);
19}
20
21int main(int argc, const char *argv[]) {
22 fprintf(stderr, "Hello world.\n");
23
24 std::thread t1(thread_func);
25 std::thread t2(thread_func);
26 t1.join();
27 t2.join();
28
29 fprintf(stderr, "Done.\n");
30}
31
32// CHECK: Hello world.
33// CHECK-NOT: WARNING: ThreadSanitizer
34// CHECK: Done.
35

source code of compiler-rt/test/tsan/Darwin/libcxx-call-once.mm