diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a814fd5855e0..b9536b448bb5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,7 @@ +2013-12-08 Jonathan Wakely + + * testsuite/30_threads/async/async.cc: Fix race condition in test. + 2013-12-08 Paolo Carlini * testsuite/20_util/add_const/requirements/explicit_instantiation.cc: diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc index 1f94494d0a33..05fd23cc96a5 100644 --- a/libstdc++-v3/testsuite/30_threads/async/async.cc +++ b/libstdc++-v3/testsuite/30_threads/async/async.cc @@ -29,23 +29,18 @@ using namespace std; -struct work { - typedef void result_type; - void operator()(mutex& m, condition_variable& cv) - { - unique_lock l(m); - cv.notify_one(); - } -}; +void work(mutex& m) +{ + unique_lock l(m); +} void test01() { mutex m; - condition_variable cv; unique_lock l(m); - future f1 = async(launch::async, work(), ref(m), ref(cv)); - cv.wait(l); - f1.get(); + future f1 = async(launch::async, &work, ref(m)); + l.unlock(); // allow async thread to proceed + f1.get(); // wait for it to finish } void test02() @@ -53,15 +48,15 @@ void test02() bool test __attribute__((unused)) = true; mutex m; - condition_variable cv; unique_lock l(m); - future f1 = async(launch::async, work(), ref(m), ref(cv)); + future f1 = async(launch::async, &work, ref(m)); std::future_status status; status = f1.wait_for(std::chrono::milliseconds(1)); VERIFY( status == std::future_status::timeout ); status = f1.wait_until(std::chrono::system_clock::now()); VERIFY( status == std::future_status::timeout ); - cv.wait(l); + l.unlock(); // allow async thread to proceed + f1.wait(); // wait for it to finish status = f1.wait_for(std::chrono::milliseconds(0)); VERIFY( status == std::future_status::ready ); status = f1.wait_until(std::chrono::system_clock::now());