| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// UNSUPPORTED: no-threads |
| 10 |
|
| 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 |
|
| 25 |
std::condition_variable_any* cv; |
| 26 |
std::mutex m; |
| 27 |
|
| 28 |
bool f_ready = false; |
| 29 |
bool g_ready = false; |
| 30 |
|
| 31 |
void f() |
| 32 |
{ |
| 33 |
m.lock(); |
| 34 |
f_ready = true; |
| 35 |
cv->notify_one(); |
| 36 |
delete cv; |
| 37 |
m.unlock(); |
| 38 |
} |
| 39 |
|
| 40 |
void 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 |
|
| 50 |
int 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 |
} |