[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.mutex / thread.once / thread.once.callonce / race.pass.cpp
blob1bc608afef3536d97473ac18911d4cf42b1b8f57
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
11 // <mutex>
13 // struct once_flag;
15 // template<class Callable, class ...Args>
16 // void call_once(once_flag& flag, Callable&& func, Args&&... args);
18 // This test is supposed to be run with ThreadSanitizer and verifies that
19 // call_once properly synchronizes user state, a data race that was fixed
20 // in r280621.
22 #include <mutex>
23 #include <thread>
24 #include <cassert>
26 #include "make_test_thread.h"
27 #include "test_macros.h"
29 std::once_flag flg0;
30 long global = 0;
32 void init0()
34 ++global;
37 void f0()
39 std::call_once(flg0, init0);
40 assert(global == 1);
43 int main(int, char**)
45 std::thread t0 = support::make_test_thread(f0);
46 std::thread t1 = support::make_test_thread(f0);
47 t0.join();
48 t1.join();
49 assert(global == 1);
51 return 0;