52 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// notify_all_at_thread_exit(...) requires move semantics to transfer the unique_lock.12// UNSUPPORTED: c++0313 14// <condition_variable>15//16// void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);17 18#include <condition_variable>19#include <mutex>20#include <thread>21#include <chrono>22#include <cassert>23 24#include "make_test_thread.h"25#include "test_macros.h"26 27std::condition_variable cv;28std::mutex mut;29 30typedef std::chrono::milliseconds ms;31typedef std::chrono::high_resolution_clock Clock;32 33void func()34{35 std::unique_lock<std::mutex> lk(mut);36 std::notify_all_at_thread_exit(cv, std::move(lk));37 std::this_thread::sleep_for(ms(300));38}39 40int main(int, char**)41{42 std::unique_lock<std::mutex> lk(mut);43 std::thread t = support::make_test_thread(func);44 Clock::time_point t0 = Clock::now();45 cv.wait(lk);46 Clock::time_point t1 = Clock::now();47 assert(t1-t0 > ms(250));48 t.join();49 50 return 0;51}52