mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-24 07:40:26 +08:00
* testsuite/30_threads/async/async.cc: Fix race condition in test.
From-SVN: r205795
This commit is contained in:
parent
7337ddf4bf
commit
da18dcc133
@ -1,3 +1,7 @@
|
||||
2013-12-08 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
* testsuite/30_threads/async/async.cc: Fix race condition in test.
|
||||
|
||||
2013-12-08 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* testsuite/20_util/add_const/requirements/explicit_instantiation.cc:
|
||||
|
@ -29,23 +29,18 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct work {
|
||||
typedef void result_type;
|
||||
void operator()(mutex& m, condition_variable& cv)
|
||||
{
|
||||
unique_lock<mutex> l(m);
|
||||
cv.notify_one();
|
||||
}
|
||||
};
|
||||
void work(mutex& m)
|
||||
{
|
||||
unique_lock<mutex> l(m);
|
||||
}
|
||||
|
||||
void test01()
|
||||
{
|
||||
mutex m;
|
||||
condition_variable cv;
|
||||
unique_lock<mutex> l(m);
|
||||
future<void> f1 = async(launch::async, work(), ref(m), ref(cv));
|
||||
cv.wait(l);
|
||||
f1.get();
|
||||
future<void> 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<mutex> l(m);
|
||||
future<void> f1 = async(launch::async, work(), ref(m), ref(cv));
|
||||
future<void> 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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user