File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
libcxx/test/std/thread/futures/futures.async Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 2020#include < atomic>
2121#include < future>
2222#include < mutex>
23+ #include < condition_variable>
24+ #include < thread>
25+ #include < chrono>
2326
2427std::mutex mux;
2528
2629int main (int , char **) {
27- using namespace std ::chrono_literals ;
30+ std::condition_variable cond ;
2831 std::unique_lock lock (mux);
29- std::atomic<bool > in_async = false ;
30- auto v = std::async (std::launch::async, [&in_async, value = 1 ]() mutable {
31- in_async = true ;
32- in_async.notify_all ();
32+ auto v = std::async (std::launch::async, [&cond, value = 1 ]() mutable {
3333 std::unique_lock thread_lock (mux);
34+ cond.notify_all ();
35+ thread_lock.unlock ();
36+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
37+
3438 value = 4 ;
3539 (void )value;
3640 });
37- in_async.wait (false );
38- lock.unlock ();
41+ cond.wait (lock);
3942
4043 return 0 ;
4144}
You can’t perform that action at this time.
0 commit comments