64 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// <condition_variable>12 13// class condition_variable_any;14 15// ~condition_variable_any();16 17#include <condition_variable>18#include <mutex>19#include <thread>20#include <cassert>21 22#include "make_test_thread.h"23#include "test_macros.h"24 25std::condition_variable_any* cv;26std::mutex m;27 28bool f_ready = false;29bool g_ready = false;30 31void f()32{33 m.lock();34 f_ready = true;35 cv->notify_one();36 delete cv;37 m.unlock();38}39 40void g()41{42 m.lock();43 g_ready = true;44 cv->notify_one();45 while (!f_ready)46 cv->wait(m);47 m.unlock();48}49 50int main(int, char**)51{52 cv = new std::condition_variable_any;53 std::thread th2 = support::make_test_thread(g);54 m.lock();55 while (!g_ready)56 cv->wait(m);57 m.unlock();58 std::thread th1 = support::make_test_thread(f);59 th1.join();60 th2.join();61 62 return 0;63}64