From e95391f67ab448fda23c6ec5f29d473992ac45ec Mon Sep 17 00:00:00 2001 From: redi Date: Wed, 20 Nov 2013 20:59:19 +0000 Subject: PR libstdc++/49204 * include/std/future (__future_base::_State_base): Rename to __future_base::_State_baseV2. (__future_base::_State_baseV2::~_State_baseV2): Define as defaulted. (__future_base::_State_baseV2::_M_run_deferred): Rename to _M_complete_async. (__future_base::_State_baseV2::_M_has_deferred): Add new virtual. (__future_base::_State_baseV2::wait_for): Call _M_has_deferred() to test for a deferred function, or call _M_complete_async() to join an async thread that has made the shared state ready. (__future_base::_State_baseV2::wait_until): Likewise. (__future_base::_Async_state_common): Rename to _Async_state_commonV2. (__future_base::_Async_state_commonV2::_M_run_deferred): Rename to _M_complete_async. * src/c++11/compatibility-thread-c++0x.cc (__future_base::_State_base): Export old definition. (__future_base::_Async_state_common): Likewise. * src/c++11/future.cc (__future_base::_State_base::~_State_base): Remove. * doc/xml/manual/status_cxx2011.xml: Update status. * testsuite/30_threads/async/async.cc: Test future_status::timeout and future_status::ready. * testsuite/30_threads/async/sync.cc: Test future_status::deferred. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205144 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/testsuite/30_threads/async/sync.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'libstdc++-v3/testsuite/30_threads/async/sync.cc') diff --git a/libstdc++-v3/testsuite/30_threads/async/sync.cc b/libstdc++-v3/testsuite/30_threads/async/sync.cc index e9b112ddf57..3e9cd34cd55 100644 --- a/libstdc++-v3/testsuite/30_threads/async/sync.cc +++ b/libstdc++-v3/testsuite/30_threads/async/sync.cc @@ -39,12 +39,32 @@ void test01() using namespace std; int a = 1; - int b = 10; - int c = 100; + int b = 1; + int c = 1; future f1 = async(launch::deferred, sum(), a, ref(b), cref(c)); + a = 0; + b = 10; + c = 100; + + const std::chrono::seconds delay(10); + const auto then = std::chrono::system_clock::now() + delay; VERIFY( f1.valid() ); + // timed waiting functions should return 'deferred' immediately + VERIFY( f1.wait_until(then) == std::future_status::deferred ); + VERIFY( f1.wait_for(delay) == std::future_status::deferred ); + VERIFY( std::chrono::system_clock::now() < then ); + + f1.wait(); + + VERIFY( f1.valid() ); + // timed waiting functions should return 'ready' immediately + VERIFY( f1.wait_until(then) == std::future_status::ready ); + VERIFY( f1.wait_for(delay) == std::future_status::ready ); + VERIFY( std::chrono::system_clock::now() < then ); + VERIFY( f1.get() == 111 ); + VERIFY( !f1.valid() ); } int main() -- cgit v1.2.1