15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier //
9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads
105a83710eSEric Fiselier 
111e051aabSEric Fiselier // notify_all_at_thread_exit(...) requires move semantics to transfer the
121e051aabSEric Fiselier // unique_lock.
1331cbe0f2SLouis Dionne // UNSUPPORTED: c++03
141e051aabSEric Fiselier 
155a83710eSEric Fiselier // <condition_variable>
165a83710eSEric Fiselier 
175a83710eSEric Fiselier // void
185a83710eSEric Fiselier //   notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
195a83710eSEric Fiselier 
205a83710eSEric Fiselier #include <condition_variable>
215a83710eSEric Fiselier #include <mutex>
225a83710eSEric Fiselier #include <thread>
235a83710eSEric Fiselier #include <chrono>
245a83710eSEric Fiselier #include <cassert>
255a83710eSEric Fiselier 
2656462801SLouis Dionne #include "make_test_thread.h"
277fc6a556SMarshall Clow #include "test_macros.h"
287fc6a556SMarshall Clow 
295a83710eSEric Fiselier std::condition_variable cv;
305a83710eSEric Fiselier std::mutex mut;
315a83710eSEric Fiselier 
325a83710eSEric Fiselier typedef std::chrono::milliseconds ms;
335a83710eSEric Fiselier typedef std::chrono::high_resolution_clock Clock;
345a83710eSEric Fiselier 
func()355a83710eSEric Fiselier void func()
365a83710eSEric Fiselier {
375a83710eSEric Fiselier     std::unique_lock<std::mutex> lk(mut);
385a83710eSEric Fiselier     std::notify_all_at_thread_exit(cv, std::move(lk));
395a83710eSEric Fiselier     std::this_thread::sleep_for(ms(300));
405a83710eSEric Fiselier }
415a83710eSEric Fiselier 
main(int,char **)422df59c50SJF Bastien int main(int, char**)
435a83710eSEric Fiselier {
445a83710eSEric Fiselier     std::unique_lock<std::mutex> lk(mut);
4556462801SLouis Dionne     std::thread t = support::make_test_thread(func);
465a83710eSEric Fiselier     Clock::time_point t0 = Clock::now();
475a83710eSEric Fiselier     cv.wait(lk);
485a83710eSEric Fiselier     Clock::time_point t1 = Clock::now();
495a83710eSEric Fiselier     assert(t1-t0 > ms(250));
5010967a6eSEric Fiselier     t.join();
512df59c50SJF Bastien 
522df59c50SJF Bastien   return 0;
535a83710eSEric Fiselier }
54