53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-threads10 11// <mutex>12 13// struct once_flag;14 15// template<class Callable, class ...Args>16// void call_once(once_flag& flag, Callable&& func, Args&&... args);17 18// This test is supposed to be run with ThreadSanitizer and verifies that19// call_once properly synchronizes user state, a data race that was fixed20// in r280621.21 22#include <mutex>23#include <thread>24#include <cassert>25 26#include "make_test_thread.h"27#include "test_macros.h"28 29std::once_flag flg0;30long global = 0;31 32void init0()33{34 ++global;35}36 37void f0()38{39 std::call_once(flg0, init0);40 assert(global == 1);41}42 43int main(int, char**)44{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);50 51 return 0;52}53