|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50665 - sandbox/interthreads/libs/interthreads/test
From: vicente.botet_at_[hidden]
Date: 2009-01-18 18:50:45
Author: viboes
Date: 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
New Revision: 50665
URL: http://svn.boost.org/trac/boost/changeset/50665
Log:
interthreads version 0.3
Adding fork_after and act traits
Text files modified:
sandbox/interthreads/libs/interthreads/test/Jamfile.v2 | 1
sandbox/interthreads/libs/interthreads/test/test_ae.hpp | 93 ++++++++++++++++++++++++++++++++++++++
sandbox/interthreads/libs/interthreads/test/test_launcher.cpp | 15 +++++
sandbox/interthreads/libs/interthreads/test/test_thread_pool.cpp | 21 +++++++-
sandbox/interthreads/libs/interthreads/test/test_threader.cpp | 96 ++++++++++++++++++++++-----------------
5 files changed, 180 insertions(+), 46 deletions(-)
Modified: sandbox/interthreads/libs/interthreads/test/Jamfile.v2
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/Jamfile.v2 (original)
+++ sandbox/interthreads/libs/interthreads/test/Jamfile.v2 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
@@ -46,6 +46,7 @@
{
test-suite "tests"
:
+ [ interthreads-run move_test.cpp ]
[ interthreads-run test_basic_threader.cpp ]
[ interthreads-run test_launcher.cpp ]
[ interthreads-run test_threader.cpp ]
Modified: sandbox/interthreads/libs/interthreads/test/test_ae.hpp
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/test_ae.hpp (original)
+++ sandbox/interthreads/libs/interthreads/test/test_ae.hpp 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
@@ -25,12 +25,21 @@
namespace bfus = boost::fusion;
int test_value;
+int test_value1;
int test_value2;
+int test_value3;
int simple_thread() {
test_value=999;
sleep(2);
return test_value;
}
+static std::string test_string_value;
+
+std::string simple_string_thread() {
+ test_string_value="999";
+ sleep(5);
+ return test_string_value;
+}
int simple_thread2() {
test_value2=111;
@@ -52,6 +61,30 @@
return failed;
}
+int my_simple_thread() {
+ test_value1=111;
+ sleep(2);
+ return test_value1;
+}
+
+int my_simple_thread2() {
+ test_value2=222;
+ sleep(3);
+ return test_value2;
+}
+
+int my_simple_thread3() {
+ test_value3=333;
+ sleep(1);
+ return test_value3;
+}
+
+int my_simple_thread4(int i, std::string s) {
+ test_value3=333;
+ sleep(1);
+ return test_value3;
+}
+
namespace aetst {
template <typename AE>
@@ -210,5 +243,65 @@
act.wait();
BOOST_CHECK(!failed);
}
+
+
+template <typename AE>
+void do_test_fork_after_get(AE& ae) {
+ test_value=0;
+ test_value2=0;
+ test_value3=0;
+ BOOST_AUTO(actT, fork_all(ae, my_simple_thread, my_simple_thread2));
+
+ #ifndef ACT_WRAPPER
+ typename AE:: template handle<int>::type res;
+ bith::fork_after(ae, my_simple_thread3, actT, res);
+ sleep(5);
+ #else
+ BOOST_AUTO(act,bith::fork_after(ae, my_simple_thread3, actT));
+ #endif
+
+ int res =act.get();
+ BOOST_CHECK_EQUAL(test_value3, 333);
+ BOOST_CHECK_EQUAL(res, 333);
+}
+template <typename AE>
+void do_test_fork_after_wait(AE& ae) {
+ test_value=0;
+ test_value2=0;
+ test_value3=0;
+ BOOST_AUTO(actT, fork_all(ae, my_simple_thread, my_simple_thread2));
+
+ #ifndef ACT_WRAPPER
+ typename AE:: template handle<int>::type res;
+ bith::fork_after(ae, my_simple_thread3, actT, res);
+ sleep(5);
+ #else
+ BOOST_AUTO(act,bith::fork_after(ae, my_simple_thread3, actT));
+ #endif
+ act.wait();
+
+ BOOST_CHECK_EQUAL(test_value3, 333);
+
+}
+template <typename AE>
+void do_test_fork_after_join(AE& ae) {
+ test_value=0;
+ test_value2=0;
+ test_value3=0;
+ BOOST_AUTO(actT, fork_all(ae, my_simple_thread, my_simple_thread2));
+
+ #ifndef ACT_WRAPPER
+ typename AE:: template handle<int>::type res;
+ bith::fork_after(ae, my_simple_thread3, actT, res);
+ sleep(5);
+ #else
+ BOOST_AUTO(act,bith::fork_after(ae, my_simple_thread3, actT));
+ #endif
+ act.join();
+
+ BOOST_CHECK_EQUAL(test_value3, 333);
+
+}
+
}
#endif
Modified: sandbox/interthreads/libs/interthreads/test/test_launcher.cpp
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/test_launcher.cpp (original)
+++ sandbox/interthreads/libs/interthreads/test/test_launcher.cpp 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
@@ -118,11 +118,20 @@
aetst::do_test_wait_for_all(ae);
}
+void do_test_fork_after_wait() {
+ bith::shared_launcher ae;
+ aetst::do_test_fork_after_wait(ae);
+}
+void do_test_fork_after_get() {
+ bith::shared_launcher ae;
+ aetst::do_test_fork_after_get(ae);
+}
+
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("launcher");
- test->add(BOOST_TEST_CASE(&do_test_member_fork_move));
+ test->add(BOOST_TEST_CASE(&do_test_member_fork_move));
test->add(BOOST_TEST_CASE(&do_test_member_fork));
test->add(BOOST_TEST_CASE(&do_test_member_fork_move));
test->add(BOOST_TEST_CASE(&do_test_member_fork_bind));
@@ -137,6 +146,10 @@
test->add(BOOST_TEST_CASE(&do_test_wait_for_any));
test->add(BOOST_TEST_CASE(&do_test_set_all));
test->add(BOOST_TEST_CASE(&do_test_wait_for_all));
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_wait));
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_get));
+ #if 0
+ #endif
return test;
}
Modified: sandbox/interthreads/libs/interthreads/test/test_thread_pool.cpp
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/test_thread_pool.cpp (original)
+++ sandbox/interthreads/libs/interthreads/test/test_thread_pool.cpp 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
@@ -38,7 +38,7 @@
#define SCHEDULER
-#if SCHEDULER
+#ifdef SCHEDULER
typedef bith::scheduler<
boost::tp::unbounded_channel< boost::tp::fifo >
> pool_type;
@@ -107,9 +107,20 @@
aetst::do_test_wait_for_all(ae);
}
+#if 0 // DO NOT COMPILE
+void do_test_fork_after_wait() {
+ pool_type ae(boost::tp::poolsize(2));
+ aetst::do_test_fork_after_wait(ae);
+}
+void do_test_fork_after_get() {
+ pool_type ae(boost::tp::poolsize(2));
+ aetst::do_test_fork_after_get(ae);
+}
+#endif
+
test_suite* init_unit_test_suite(int, char*[])
{
- test_suite* test = BOOST_TEST_SUITE("shared_threader");
+ test_suite* test = BOOST_TEST_SUITE("scheduler");
test->add(BOOST_TEST_CASE(&do_test_member_fork));
test->add(BOOST_TEST_CASE(&do_test_member_fork_bind));
@@ -119,8 +130,12 @@
test->add(BOOST_TEST_CASE(&do_test_creation_through_functor));
test->add(BOOST_TEST_CASE(&do_test_creation_through_reference_wrapper));
test->add(BOOST_TEST_CASE(&do_test_wait_all));
- //test->add(BOOST_TEST_CASE(&do_test_wait_for_any)); FAILS
test->add(BOOST_TEST_CASE(&do_test_set_all));
test->add(BOOST_TEST_CASE(&do_test_wait_for_all));
+#if 0
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_wait)); // DO NOT COMPILE
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_get)); // DO NOT COMPILE
+ test->add(BOOST_TEST_CASE(&do_test_wait_for_any)); // FAILS
+#endif
return test;
}
Modified: sandbox/interthreads/libs/interthreads/test/test_threader.cpp
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/test_threader.cpp (original)
+++ sandbox/interthreads/libs/interthreads/test/test_threader.cpp 2009-01-18 18:50:44 EST (Sun, 18 Jan 2009)
@@ -18,16 +18,25 @@
#include "boost/interthreads/typeof/threader.hpp"
#include "boost/interthreads/typeof/future.hpp"
#include "boost/interthreads/algorithm.hpp"
+#ifdef FORK_AFTER
+#endif
+#include "boost/interthreads/fork_after.hpp"
#include <boost/typeof/typeof.hpp>
#include <libs/interthreads/test/data_types.hpp>
#include <libs/interthreads/test/test_ae.hpp>
#include <iostream>
+#include <string>
#include <boost/test/unit_test.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
+
+//#include "boost/fusion/include/begin.hpp"
+//#include "boost/fusion/include/end.hpp"
+//#include "boost/fusion/include/next.hpp"
+
using namespace boost::unit_test;
namespace bith = boost::interthreads;
namespace bfus = boost::fusion;
@@ -76,7 +85,6 @@
aetst::do_test_creation_through_functor(ae);
}
-
void do_test_thread_interrupts_at_interruption_point() {
bith::shared_threader ae;
aetst::do_test_thread_interrupts_at_interruption_point(ae);
@@ -96,52 +104,37 @@
aetst::do_test_wait_for_any(ae);
}
-void do_test_wait_for_any2() {
- boost::packaged_task<int> tsk1(simple_thread);
- boost::unique_future<int> res1 = tsk1.get_future();
- boost::thread th1(boost::move(tsk1));
- boost::packaged_task<int> tsk2(simple_thread2);
- boost::unique_future<int> res2 = tsk2.get_future();
- boost::thread th2(boost::move(tsk2));
- unsigned res = boost::wait_for_any(res1, res2);
-
- BOOST_CHECK_EQUAL(res, 0u);
+template<typename AE>
+struct waiter_add {
+ waiter_add(boost::detail::future_waiter& waiter) : waiter_(waiter) {}
+ boost::detail::future_waiter& waiter_;
+ typedef void result_type;
+ template<typename ACT>
+ void operator()(ACT& act) const {
+ waiter_.add(bith::get_future<AE>()(act));
+ }
+};
+
+
+template<typename AE, typename FusionSequence>
+unsigned my_wait_for_any(FusionSequence& seq) {
+ boost::detail::future_waiter waiter;
+ boost::fusion::for_each(seq, waiter_add<AE>(waiter));
+ return waiter.wait();
}
-void do_test_wait_for_any3() {
- bith::shared_threader ae;
+void do_test_wait_for_any_fusion_sequence()
+{
typedef bith::shared_threader AE;
- typedef bith::result_of::fork_all<bith::shared_threader,bfus::tuple<int(*)(),int(*)()> >::type type;
- type tple = bith::fork_all(ae, simple_thread, simple_thread);
- unsigned r = boost::wait_for_any(
- bith::get_future<AE>()(bfus::at_c<0>(tple)),
- bith::get_future<AE>()(bfus::at_c<1>(tple)));
- int val;
- switch (r) {
- case 0:
- val = bfus::at_c<0>(tple).get();
- break;
- case 1:
- val = bfus::at_c<1>(tple).get();
- break;
- default:;
- //throw std::range_error("");
- }
+ AE ae;
+ typedef bith::result_of::fork_all<bith::shared_threader,bfus::tuple<int(*)(),std::string(*)()> >::type type;
+ type tple = bith::fork_all(ae, simple_thread, simple_string_thread);
+ unsigned r = my_wait_for_any<AE>(tple);
bith::interrupt_all(tple);
BOOST_CHECK_EQUAL(r, 0u);
}
-void do_test_other() {
- boost::packaged_task<int> tsk1(simple_thread);
- boost::packaged_task<int> tsk2(simple_thread2);
- boost::unique_future<int> res1 = tsk1.get_future();
- //BOOST_AUTO(res1,tsk1.get_future());
- boost::unique_future<int> res2 = tsk2.get_future();
- boost::thread th1(boost::move(tsk1));
- boost::thread th2(boost::move(tsk2));
-
-}
-
+#if 0
void do_test_get_all() {
bith::shared_threader ae;
typedef bith::result_of::fork_all<bith::shared_threader,bfus::tuple<int(*)(),int(*)()> >::type auto_type;
@@ -151,6 +144,7 @@
BOOST_AUTO(res,bith::get_all(tple));
//bfus::for_each(res, print_xml());
}
+#endif
void do_test_set_all() {
bith::shared_threader ae;
@@ -162,6 +156,21 @@
aetst::do_test_wait_for_all(ae);
}
+void do_test_fork_after_join() {
+ bith::shared_threader ae;
+ aetst::do_test_fork_after_join(ae);
+}
+
+void do_test_fork_after_wait() {
+ bith::shared_threader ae;
+ aetst::do_test_fork_after_wait(ae);
+}
+
+void do_test_fork_after_get() {
+ bith::shared_threader ae;
+ aetst::do_test_fork_after_get(ae);
+}
+
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("shared_threader");
@@ -175,13 +184,16 @@
test->add(BOOST_TEST_CASE(&do_test_creation_through_functor));
test->add(BOOST_TEST_CASE(&do_test_creation_through_reference_wrapper));
test->add(BOOST_TEST_CASE(&do_test_wait_all));
- test->add(BOOST_TEST_CASE(&do_test_wait_for_any2));
test->add(BOOST_TEST_CASE(&do_test_join_all));
test->add(BOOST_TEST_CASE(&do_test_wait_for_any));
test->add(BOOST_TEST_CASE(&do_test_set_all));
test->add(BOOST_TEST_CASE(&do_test_wait_for_all));
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_join));
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_wait));
+ test->add(BOOST_TEST_CASE(&do_test_fork_after_get));
+ test->add(BOOST_TEST_CASE(&do_test_wait_for_any_fusion_sequence));
#if 0
- //test->add(BOOST_TEST_CASE(&do_test_get_all));
+ test->add(BOOST_TEST_CASE(&do_test_get_all));
#endif
return test;
}
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