|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84911 - in trunk/libs/thread/test: . sync/mutual_exclusion/sync_bounded_queue sync/mutual_exclusion/sync_queue
From: vicente.botet_at_[hidden]
Date: 2013-06-28 02:00:44
Author: viboes
Date: 2013-06-28 02:00:44 EDT (Fri, 28 Jun 2013)
New Revision: 84911
URL: http://svn.boost.org/trac/boost/changeset/84911
Log:
Thread: make use of barrier on test sync_queue/multi_thread_pass.cpp and remove some warnings in sync_queue|sync_bounded_queue/single_thread_pass.cpp tests.
Text files modified:
trunk/libs/thread/test/Jamfile.v2 | 2
trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp | 40 ++++++++++----------
trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp | 80 +++++++++++++---------------------------
trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp | 34 ++++++++--------
4 files changed, 64 insertions(+), 92 deletions(-)
Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 Thu Jun 27 14:40:41 2013 (r84910)
+++ trunk/libs/thread/test/Jamfile.v2 2013-06-28 02:00:44 EDT (Fri, 28 Jun 2013) (r84911)
@@ -633,6 +633,7 @@
test-suite ts_sync_queue
:
[ thread-run2-noit ./sync/mutual_exclusion/sync_queue/single_thread_pass.cpp : sync_queue__single_thread_p ]
+ [ thread-run2-noit ./sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp : sync_queue__multi_thread_p ]
;
test-suite ts_sync_bounded_queue
@@ -789,7 +790,6 @@
#[ thread-run test_8596.cpp ]
#[ thread-run test_8600.cpp ]
#[ thread-run2-noit ./sync/mutual_exclusion/sync_bounded_queue/multi_thread_pass.cpp : sync_bounded_queue__multi_thread_p ]
- [ thread-run2-noit ./sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp : sync_queue__multi_thread_p ]
;
Modified: trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp Thu Jun 27 14:40:41 2013 (r84910)
+++ trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp 2013-06-28 02:00:44 EDT (Fri, 28 Jun 2013) (r84911)
@@ -23,8 +23,8 @@
boost::sync_bounded_queue<int> q(2);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
- BOOST_TEST_EQ(q.capacity(), 2);
+ BOOST_TEST_EQ(q.size(), 0u);
+ BOOST_TEST_EQ(q.capacity(), 2u);
BOOST_TEST(! q.closed());
}
{
@@ -34,7 +34,7 @@
BOOST_TEST(! q.try_pull(i));
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -43,7 +43,7 @@
BOOST_TEST(! q.try_pull());
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -52,7 +52,7 @@
q.push(1);
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -62,7 +62,7 @@
q.push(2);
BOOST_TEST(! q.empty());
BOOST_TEST( q.full());
- BOOST_TEST_EQ(q.size(), 2);
+ BOOST_TEST_EQ(q.size(), 2u);
BOOST_TEST(! q.closed());
}
{
@@ -72,7 +72,7 @@
q.push(i);
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -81,7 +81,7 @@
BOOST_TEST(q.try_push(1));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -91,7 +91,7 @@
BOOST_TEST(q.try_push(i));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -100,7 +100,7 @@
BOOST_TEST(q.try_push(boost::no_block, 1));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -112,7 +112,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -123,7 +123,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -135,7 +135,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -147,7 +147,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -158,7 +158,7 @@
BOOST_TEST_EQ(*i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -169,7 +169,7 @@
BOOST_TEST(! q.try_push(3));
BOOST_TEST(! q.empty());
BOOST_TEST( q.full());
- BOOST_TEST_EQ(q.size(), 2);
+ BOOST_TEST_EQ(q.size(), 2u);
BOOST_TEST(! q.closed());
}
{
@@ -180,7 +180,7 @@
BOOST_TEST(q.try_pull());
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
@@ -190,7 +190,7 @@
q.close();
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
{
@@ -203,7 +203,7 @@
} catch (...) {
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
}
@@ -217,7 +217,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
Modified: trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp Thu Jun 27 14:40:41 2013 (r84910)
+++ trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/multi_thread_pass.cpp 2013-06-28 02:00:44 EDT (Fri, 28 Jun 2013) (r84911)
@@ -17,57 +17,51 @@
#define BOOST_THREAD_VERSION 4
#include <boost/thread/sync_queue.hpp>
-#include <boost/thread/thread_only.hpp>
#include <boost/thread/future.hpp>
+#include <boost/thread/barrier.hpp>
#include <boost/detail/lightweight_test.hpp>
struct call_push
{
boost::sync_queue<int> &q_;
- boost::shared_future<void> ready_;
- boost::promise<void> &op_ready_;
+ boost::barrier& go_;
- call_push(boost::sync_queue<int> &q, boost::shared_future<void> ready, boost::promise<void> &op_ready) :
- q_(q), ready_(ready), op_ready_(op_ready)
+ call_push(boost::sync_queue<int> &q, boost::barrier &go) :
+ q_(q), go_(go)
{
}
typedef void result_type;
void operator()()
{
- op_ready_.set_value();
- ready_.wait();
+ go_.count_down_and_wait();
q_.push(42);
- }
+ }
};
struct call_pull
{
boost::sync_queue<int> &q_;
- boost::shared_future<void> ready_;
- boost::promise<void> &op_ready_;
+ boost::barrier& go_;
- call_pull(boost::sync_queue<int> &q, boost::shared_future<void> ready, boost::promise<void> &op_ready) :
- q_(q), ready_(ready), op_ready_(op_ready)
+ call_pull(boost::sync_queue<int> &q, boost::barrier &go) :
+ q_(q), go_(go)
{
}
typedef int result_type;
int operator()()
{
- op_ready_.set_value();
- ready_.wait();
+ go_.count_down_and_wait();
return q_.pull();
}
-
};
void test_concurrent_push_and_pull_on_empty_queue()
{
boost::sync_queue<int> q;
- boost::promise<void> go, push_ready, pull_ready;
- boost::shared_future<void> ready(go.get_future());
+ boost::barrier go(2);
boost::future<void> push_done;
boost::future<int> pull_done;
@@ -76,31 +70,26 @@
{
push_done=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
- [&q,ready,&push_ready]()
+ [&q,&go]()
{
- push_ready.set_value();
- ready.wait();
+ go.wait();
q.push(42);
}
#else
- call_push(q,ready,push_ready)
+ call_push(q,go)
#endif
);
pull_done=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
- [&q,ready,&pull_ready]()
+ [&q,&go]()
{
- pull_ready.set_value();
- ready.wait();
+ go.wait();
return q.pull();
}
#else
- call_pull(q,ready,pull_ready)
+ call_pull(q,go)
#endif
);
- push_ready.get_future().wait();
- pull_ready.get_future().wait();
- go.set_value();
push_done.get();
BOOST_TEST_EQ(pull_done.get(), 42);
@@ -108,7 +97,6 @@
}
catch (...)
{
- go.set_value();
BOOST_TEST(false);
}
}
@@ -117,10 +105,7 @@
{
boost::sync_queue<int> q;
const unsigned int n = 3;
- boost::promise<void> go;
- boost::shared_future<void> ready(go.get_future());
-
- boost::promise<void> push_ready[n];
+ boost::barrier go(n);
boost::future<void> push_done[n];
try
@@ -128,23 +113,19 @@
for (unsigned int i =0; i< n; ++i)
push_done[i]=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
- [&q,ready,&push_ready,i]()
+ [&q,&go]()
{
- push_ready[i].set_value();
- ready.wait();
+ go.wait();
q.push(42);
}
#else
- call_push(q,ready,push_ready[i])
+ call_push(q,go)
#endif
);
for (unsigned int i = 0; i < n; ++i)
- push_ready[i].get_future().wait();
- go.set_value();
-
- for (unsigned int i = 0; i < n; ++i)
push_done[i].get();
+
BOOST_TEST(!q.empty());
for (unsigned int i =0; i< n; ++i)
BOOST_TEST_EQ(q.pull(), 42);
@@ -153,7 +134,6 @@
}
catch (...)
{
- go.set_value();
BOOST_TEST(false);
}
}
@@ -162,10 +142,8 @@
{
boost::sync_queue<int> q;
const unsigned int n = 3;
- boost::promise<void> go;
- boost::shared_future<void> ready(go.get_future());
+ boost::barrier go(n);
- boost::promise<void> pull_ready[n];
boost::future<int> pull_done[n];
try
@@ -176,28 +154,22 @@
for (unsigned int i =0; i< n; ++i)
pull_done[i]=boost::async(boost::launch::async,
#if ! defined BOOST_NO_CXX11_LAMBDAS
- [&q,ready,&pull_ready,i]()
+ [&q,&go]()
{
- pull_ready[i].set_value();
- ready.wait();
+ go.wait();
return q.pull();
}
#else
- call_pull(q,ready,pull_ready[i])
+ call_pull(q,go)
#endif
);
for (unsigned int i = 0; i < n; ++i)
- pull_ready[i].get_future().wait();
- go.set_value();
-
- for (unsigned int i = 0; i < n; ++i)
BOOST_TEST_EQ(pull_done[i].get(), 42);
BOOST_TEST(q.empty());
}
catch (...)
{
- go.set_value();
BOOST_TEST(false);
}
}
Modified: trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp Thu Jun 27 14:40:41 2013 (r84910)
+++ trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp 2013-06-28 02:00:44 EDT (Fri, 28 Jun 2013) (r84911)
@@ -23,7 +23,7 @@
boost::sync_queue<int> q;
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -33,7 +33,7 @@
BOOST_TEST(! q.try_pull(i));
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -42,7 +42,7 @@
BOOST_TEST(! q.try_pull());
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -51,7 +51,7 @@
q.push(1);
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -61,7 +61,7 @@
q.push(2);
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 2);
+ BOOST_TEST_EQ(q.size(), 2u);
BOOST_TEST(! q.closed());
}
{
@@ -71,7 +71,7 @@
q.push(i);
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -80,7 +80,7 @@
BOOST_TEST(q.try_push(1));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -90,7 +90,7 @@
BOOST_TEST(q.try_push(i));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -99,7 +99,7 @@
BOOST_TEST(q.try_push(boost::no_block, 1));
BOOST_TEST(! q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 1);
+ BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
{
@@ -111,7 +111,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -122,7 +122,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -134,7 +134,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -146,7 +146,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
{
@@ -157,7 +157,7 @@
BOOST_TEST_EQ(*i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(! q.closed());
}
@@ -167,7 +167,7 @@
q.close();
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
{
@@ -180,7 +180,7 @@
} catch (...) {
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
}
@@ -194,7 +194,7 @@
BOOST_TEST_EQ(i, 1);
BOOST_TEST(q.empty());
BOOST_TEST(! q.full());
- BOOST_TEST_EQ(q.size(), 0);
+ BOOST_TEST_EQ(q.size(), 0u);
BOOST_TEST(q.closed());
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk