Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49845 - sandbox/interthreads/libs/interthreads/example
From: vicente.botet_at_[hidden]
Date: 2008-11-19 10:54:12


Author: viboes
Date: 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
New Revision: 49845
URL: http://svn.boost.org/trac/boost/changeset/49845

Log:
interthreads version 0.1
Added:
   sandbox/interthreads/libs/interthreads/example/async_ostream.cpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/async_ostream.hpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/basic_keep_alive.cpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/hello_world.cpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/mono_thread_id.cpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/multiple_algorithms.cpp (contents, props changed)
   sandbox/interthreads/libs/interthreads/example/timestamped.hpp (contents, props changed)

Added: sandbox/interthreads/libs/interthreads/example/async_ostream.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/async_ostream.cpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,260 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+//#define CONCENTRATOR
+#include "./timestamped.hpp"
+#include "./async_ostream.hpp"
+#include <boost/interthreads/thread_decorator.hpp>
+#include <boost/interthreads/thread_specific_shared_ptr.hpp>
+
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
+
+#include <deque> // std::priority_queue
+#include <queue> // std::priority_queue
+#include <iostream> // std::ostream
+#include <sstream> // std::stringstream
+
+boost::mutex out_global_mutex;
+
+namespace boost {
+namespace interthreads {
+namespace detail {
+ typedef timestamped<std::stringstream> element_type;
+ typedef std::queue<element_type*> queue_type;
+ typedef std::priority_queue<queue_type*, std::deque<element_type*>, element_type::ptr_comparator_gt> priority_queue_type;
+
+ //==========================================================================================
+
+ struct async_ostream_thread_ctx {
+ async_ostream_thread_ctx()
+ : current_(new element_type())
+ , seq_(0)
+ {}
+
+ boost::mutex& get_mutex() {return mutex_;}
+ std::stringstream& buffer() {return current_->value_;}
+
+ std::streamsize write(const char* s, std::streamsize n) {
+ buffer().write(s, n);
+ return n;
+ }
+
+ void flush() {
+ current_->reset_date(seq_);
+ ++seq_;
+ ++nb_push;
+ if (queue_.size()>100) {
+ ++nb_push_gt_1;
+ queue_.push(current_);
+ } else {
+ boost::lock_guard<boost::mutex> lock(mutex_);
+ queue_.push(current_);
+ }
+ current_ = new element_type();
+ }
+ element_type* get() {
+ if (queue_.size()>100) {
+ ++nb_get_gt_1;
+ return get_i();
+ } else {
+ boost::lock_guard<boost::mutex> lock(mutex_);
+ return get_i();
+ }
+ }
+ void print_stats() {
+ boost::thread::id id= boost::this_thread::get_id();
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "TID=" << id <<" nb_push " << nb_push << std::endl;
+ std::cout << "TID=" << id <<" nb_push_gt_1 " << nb_push << std::endl;
+ std::cout << "TID=" << id <<" nb_get " << nb_push << std::endl;
+ std::cout << "TID=" << id <<" nb_get_gt_1 " << nb_push << std::endl;
+ std::cout << "TID=" << id <<" inc " << inc_ << std::endl;
+ };
+ bool empty() {
+ return queue_.empty();
+ }
+ void inc() {
+ ++inc_;
+ }
+
+
+ private:
+ element_type* get_i() {
+ if (queue_.empty()) {
+ ++nb_get_0;
+ return 0;
+ }
+ ++nb_get;
+ element_type* e= queue_.front();
+ queue_.pop();
+ return e;
+ }
+ element_type *current_;
+ queue_type queue_;
+ unsigned seq_;
+ boost::mutex mutex_;
+ unsigned nb_push_gt_1;
+ unsigned nb_push;
+ unsigned nb_get_gt_1;
+ unsigned nb_get_0;
+ unsigned nb_get;
+ unsigned inc_;
+ };
+
+ //==========================================================================================
+#ifdef CONCENTRATOR
+ struct async_ostream_concentrator {
+ static void loop(async_ostream_sink::impl* that);
+ async_ostream_concentrator(async_ostream_sink::impl* impl_ptr)
+ : thread_(boost::bind(loop, impl_ptr)) {}
+ ~async_ostream_concentrator() {}
+
+ private:
+ boost::thread thread_;
+ };
+#endif
+
+ //==========================================================================================
+
+ typedef thread_specific_shared_ptr<async_ostream_thread_ctx> tsss_type;
+
+ struct async_ostream_sink::impl {
+ impl(std::ostream& os)
+ : os_(os)
+ , tsss_(terminate)
+#ifndef CONCENTRATOR
+ , thread_(boost::bind(loop, this))
+#endif
+ {}
+
+ std::ostream& os_;
+ tsss_type tsss_;
+ priority_queue_type queue_;
+#ifdef CONCENTRATOR
+ boost::once_flag concentrator_flag_;
+ async_ostream_concentrator* concentrator_;
+#else
+ boost::thread thread_;
+#endif
+
+ static void terminate(shared_ptr<async_ostream_thread_ctx> that) {
+ while (!that->empty()) {
+ that->inc();
+ }
+ //that->print_stats();
+ }
+
+#ifdef CONCENTRATOR
+ static void create_concentrator_once(impl* that) {
+ that->concentrator_ = new async_ostream_concentrator(that);
+ }
+ void create_concentrator() {
+ boost::call_once(concentrator_flag_,
+ boost::bind(create_concentrator_once, this));
+ }
+#else
+ static void loop(impl* that);
+#endif
+
+ std::streamsize write(const char* s, std::streamsize n) {
+ return tsss_->write(s, n);
+ }
+
+ void flush() {
+ tsss_->flush();
+ }
+
+
+ };
+
+ //==========================================================================================
+
+ async_ostream_sink::async_ostream_sink(std::ostream& os)
+ : impl_(new async_ostream_sink::impl(os)) {}
+
+ std::streamsize async_ostream_sink::write(const char* s, std::streamsize n) {
+ return impl_->write(s,n);
+ }
+
+ void async_ostream_sink::flush() {
+ return impl_->flush();
+ }
+
+#ifdef CONCENTRATOR
+ void async_ostream_concentrator::loop(async_ostream_sink::impl* that) {
+#else
+ void async_ostream_sink::impl::loop(async_ostream_sink::impl* that) {
+#endif
+ std::ostream& os_ = that->os_;
+ for(;;)
+ {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(1));
+ { // scope needed don't remove
+ tsss_type::lock_type lock(that->tsss_.get_mutex());
+ const tsss_type::map_type& tmap(that->tsss_.get_map(lock));
+ for (tsss_type::map_type::const_iterator it = tmap.begin(); it != tmap.end(); ++it) {
+ for(int i=0;i<1;++i) {
+ element_type* e= it->second->get();
+ if (e ==0) break;
+ that->queue_.push(e);
+ }
+ }
+ //it->second->print_stats();
+ }
+ if (that->queue_.empty()) {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ } else {
+ element_type* e = that->queue_.top();
+ that->queue_.pop();
+ #ifdef XTIME
+ os_ << e->seq_ << "["<<e->date_.sec<<":"<<e->date_.nsec<<"]| " << e->value_.str();
+ #else
+ os_ << e->seq_ << "| " << e->value_.str();
+ #endif
+ delete e;
+ }
+
+ }
+ }
+
+}
+
+ //==========================================================================================
+
+
+ async_ostream::async_ostream(std::ostream& os)
+ : base_type(os)
+ {}
+
+ void async_ostream::flush() {
+ this->base_type::flush();
+ async_ostream& d = *this;
+ d->flush();
+ }
+
+ //==========================================================================================
+
+ async_ostream cout_(std::cout);
+
+ void async_ostream::thread_specific_setup() {
+ cout_->impl_->tsss_.reset(new detail::async_ostream_thread_ctx());
+#ifdef CONCENTRATOR
+ cout_->impl_->create_concentrator();
+#endif
+ }
+
+ namespace detail {
+ thread_decoration async_ostream_decoration(boost::interthreads::async_ostream::thread_specific_setup);
+ }
+
+}
+}
+
+

Added: sandbox/interthreads/libs/interthreads/example/async_ostream.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/async_ostream.hpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,44 @@
+#ifndef BOOST_INTERTHREADS_ASYNC_OSTREAM_HPP
+#define BOOST_INTERTHREADS_ASYNC_OSTREAM_HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "./detail/async_ostream_sink.hpp"
+
+#include <boost/iostreams/categories.hpp> // iostreams::sink_tag
+#include <boost/iostreams/stream.hpp> // iostreams::stream
+
+#include <iosfwd> // std::streamsize
+#include <iostream> // std::ostream
+#include <iostream> // std::cout
+
+
+namespace boost {
+namespace interthreads {
+ class async_ostream : public iostreams::stream<detail::async_ostream_sink> {
+ public:
+ typedef iostreams::stream<detail::async_ostream_sink> base_type;
+ typedef char char_type;
+ typedef iostreams::sink_tag category;
+
+ async_ostream(std::ostream& os);
+ void flush();
+
+ static void thread_specific_setup();
+ };
+
+ extern async_ostream cout_;
+}
+}
+
+#endif
+

Added: sandbox/interthreads/libs/interthreads/example/basic_keep_alive.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/basic_keep_alive.cpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,71 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+// Based on the shared.cpp example from the threadalert library of Roland Schwarz
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+boost::mutex out_global_mutex2;
+
+void sleep(int sec)
+{
+ boost::xtime t;
+ boost::xtime_get(&t,1);
+ t.sec += sec;
+ boost::thread::sleep(t);
+}
+
+
+ #include <boost/interthreads/thread_decorator.hpp>
+ #include <boost/interthreads/thread_keep_alive.hpp>
+ #include "./async_ostream.cpp"
+ #include "./async_ostream.hpp"
+ #include <boost/thread/thread.hpp>
+ #include <iostream>
+ #include <sstream>
+
+ namespace bith = boost::interthreads;
+
+ void my_thread() {
+ bith::this_thread::enable_keep_alive enabler;
+ for (int i=0; i<10; i++) {
+ bith::this_thread::keep_alive_point();
+
+ boost::thread::id id= boost::this_thread::get_id();
+ std::stringstream sss;
+#define COUT_
+#ifdef COUT_
+ bith::cout_ << "TID=" << i << " " << id << std::endl;
+ bith::cout_.flush();
+#else
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex2);
+ std::cout << "TID=" << i << " " << id << std::endl;
+ }
+#endif
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+ }
+
+ int main() {
+ boost::thread th1(bith::make_decorator(my_thread));
+ boost::thread th2(bith::make_decorator(my_thread));
+ boost::thread th3(bith::make_decorator(my_thread));
+ boost::thread th4(bith::make_decorator(my_thread));
+ boost::thread th5(bith::make_decorator(my_thread));
+
+ th1.join();
+ th2.join();
+ th3.join();
+ th4.join();
+ th5.join();
+ sleep(2);
+ return 0;
+ }

Added: sandbox/interthreads/libs/interthreads/example/hello_world.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/hello_world.cpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,128 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+// Based on the shared.cpp example from the threadalert library of Roland Schwarz
+//////////////////////////////////////////////////////////////////////////////
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+boost::mutex out_global_mutex;
+
+ #include <iostream>
+ #include <boost/interthreads/thread_decorator.hpp>
+ #include <boost/thread.hpp>
+ #include <boost/function.hpp>
+
+ namespace bith = boost::interthreads;
+
+ void my_setup() {
+ std::cout << "Hello World!" << std::endl;
+ }
+
+ void my_cleanup() {
+ std::cout << "Bye, Bye!" << std::endl;
+ }
+
+ bith::thread_decoration my_decoration(my_setup, my_cleanup);
+
+ struct mycallable1
+ {
+ void operator()() const {
+ std::cout << "mycallable1" << std::endl;
+ };
+ };
+
+ struct mycallable2
+ {
+ void operator()() const {
+ std::cout << "mycallable2" << std::endl;
+ };
+ };
+ void my_thread() {
+ std::cout << "..." << std::endl;
+// mycallable1 x;
+// boost::this_thread::at_thread_exit(x);
+ }
+
+ template <typename F>
+ void my_test(F f) {
+ F cpy = f;
+ cpy();
+ }
+
+ struct X {
+ template <typename F>
+ X(F f) {
+ F cpy = f;
+ cpy();
+ }
+ };
+
+ int main() {
+#if 0
+ mycallable2 x;
+ boost::this_thread::at_thread_exit(x);
+// boost::thread th1(x);
+
+ bith::thread_decorator my_thread_d1(my_thread);
+ my_test(my_thread_d1);
+ X x1(my_thread_d1);
+
+ bith::thread_decorator my_thread_d2(my_thread_d1);
+ my_test(my_thread_d1);
+ X x2(my_thread_d2);
+
+ bith::thread_decorator my_thread_d3;
+ my_thread_d3 = my_thread_d2;
+ my_test(my_thread_d2);
+ X x3(my_thread_d3);
+#endif
+#if 1
+ bith::thread_decorator my_thread_d(my_thread);
+// boost::thread th(my_thread_d);
+
+// boost::detail::thread_move_t<bith::thread_decorator> mt(my_thread_d);
+// boost::thread th(mt);
+ boost::thread th(bith::make_decorator(my_thread));
+ boost::thread th2(bith::make_decorator(my_thread));
+
+// boost::function<void ()> fct(my_thread_d);
+// fct();
+// boost::thread th(boost::ref(my_thread_d));
+// boost::thread th(boost::detail::thread_move_t<bith::thread_decorator>(my_thread_d));
+// boost::thread th(boost::move(my_thread_d));
+// boost::thread th(fct);
+
+ {
+ boost::mutex::scoped_lock out_guard(out_global_mutex);
+ std::cout << "waiting1 " <<std::endl;
+ }
+ th.join();
+ {
+ boost::mutex::scoped_lock out_guard(out_global_mutex);
+ std::cout << "waiting2" <<std::endl;
+ }
+ th2.join();
+ {
+ boost::mutex::scoped_lock out_guard(out_global_mutex);
+ std::cout << "end" <<std::endl;
+ }
+#endif
+
+#if 0
+ mycallable2 c2;
+ boost::function<void ()> fct(c2);
+ boost::thread th2(fct);
+ th2.join();
+#endif
+
+// boost::thread th(my_thread_d);
+// boost::thread th(my_thread);
+
+ return 0;
+ }

Added: sandbox/interthreads/libs/interthreads/example/mono_thread_id.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/mono_thread_id.cpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,110 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+// Based on the shared.cpp example from the threadalert library of Roland Schwarz
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+boost::mutex out_global_mutex;
+
+void sleep(int sec)
+{
+ boost::xtime t;
+ boost::xtime_get(&t,1);
+ t.sec += sec;
+ boost::thread::sleep(t);
+}
+
+ #include <boost/interthreads/thread_decorator.hpp>
+ #include <boost/interthreads/thread_specific_shared_ptr.hpp>
+ #include <boost/thread/thread.hpp>
+ #include <iostream>
+
+ namespace bith = boost::interthreads;
+
+ struct mono_thread_id {
+ static bith::thread_decoration decoration_;
+ typedef bith::thread_specific_shared_ptr<unsigned> tssp_type;
+ static tssp_type current_;
+ static unsigned counter_;
+ static boost::mutex sync_;
+
+ static unsigned create() {
+ boost::lock_guard<boost::mutex> lock(sync_);
+ unsigned res = counter_;
+ ++counter_;
+ return res;
+ }
+ static void setup() {
+ std::cout << "setup" << std::endl;
+ current_.reset(new unsigned(create()));
+ }
+ public:
+ static unsigned id() {
+ return *current_;
+ }
+ static unsigned id(boost::thread::id id) {
+
+ boost::shared_ptr<unsigned> shp = current_[id];
+ if (shp.get()!=0) {
+ return *shp;
+ } else {
+ return 0xffffffff;
+ }
+ }
+
+ };
+
+ bith::thread_decoration mono_thread_id::decoration_(mono_thread_id::setup);
+ mono_thread_id::tssp_type mono_thread_id::current_;
+ unsigned mono_thread_id::counter_=0;
+ boost::mutex mono_thread_id::sync_;
+
+ void my_thread() {
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << ">> thread::id=" << boost::this_thread::get_id() << " mono_thread_id=" << mono_thread_id::id() << std::endl;
+ }
+ sleep(5);
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "<< thread::id=" << boost::this_thread::get_id() << " mono_thread_id=" << mono_thread_id::id() << std::endl;
+ }
+ }
+
+ int main() {
+ boost::thread th1(bith::make_decorator(my_thread));
+ boost::thread th2(bith::make_decorator(my_thread));
+
+ const boost::shared_ptr<unsigned> shp1 = mono_thread_id::current_.wait_and_get(th1.get_id());
+ if (shp1.get()==0) {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "ERROR 1" << std::endl;
+ }
+
+ const boost::shared_ptr<unsigned> shp2 = mono_thread_id::current_.wait_and_get(th2.get_id());
+ if (shp2.get()==0) {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "ERROR 2" << std::endl;
+ }
+
+ {
+ unsigned u = mono_thread_id::id(th1.get_id());
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "thread::id=" << th1.get_id() << " mono_thread_id="
+ << u << std::endl;
+ }
+
+ th1.join();
+ th2.join();
+
+ return 0;
+ }
+

Added: sandbox/interthreads/libs/interthreads/example/multiple_algorithms.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/multiple_algorithms.cpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,94 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+// Based on the shared.cpp example from the threadalert library of Roland Schwarz
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/thread.hpp>
+boost::mutex out_global_mutex;
+
+void sleep(int sec)
+{
+ boost::xtime t;
+ boost::xtime_get(&t,1);
+ t.sec += sec;
+ boost::thread::sleep(t);
+}
+
+
+// #include <boost/interthreads/thread_decorator.hpp>
+ #include <boost/interthreads/thread_tuple.hpp>
+ #include <boost/interthreads/thread_tuple_once.hpp>
+ #include <boost/interthreads/thread_group_once.hpp>
+ #include <boost/interthreads/thread_and_join.hpp>
+ #include <boost/thread.hpp>
+ #include <iostream>
+
+ namespace bith = boost::interthreads;
+
+ void my_thread1() {
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "1 thread_id=" << boost::this_thread::get_id() << std::endl;
+ }
+ sleep(10);
+ }
+
+ void my_thread2() {
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "2 thread_id=" << boost::this_thread::get_id() << std::endl;
+ }
+ sleep(5);
+ }
+
+ void my_thread3() {
+ {
+ boost::lock_guard<boost::mutex> lock(out_global_mutex);
+ std::cout << "3 thread_id=" << boost::this_thread::get_id() << std::endl;
+ }
+ sleep(7);
+ }
+
+ int main() {
+
+ bith::thread_tuple<3> tt_0(my_thread1, my_thread2, my_thread3);
+ bith::thread_tuple<3> tt_1;
+ tt_1= tt_0.move();
+ bith::thread_tuple<3> tt_2(tt_1.move());
+ bith::thread_tuple<3> tt(boost::move(tt_2));
+
+ tt.join_all();
+ std::cout << "All finished join_all" << std::endl;
+
+ bith::thread_tuple<3> kk_0= bith::make_thread_tuple(my_thread1, my_thread2, my_thread3);
+ kk_0.join_all();
+ std::cout << "All finished join_all" << std::endl;
+
+#if 0
+
+ bith::thread_group_once tgo;
+ boost::thread* th1 = tgo.create_thread(my_thread1);
+ boost::thread* th2 = tgo.create_thread(my_thread2);
+ boost::thread* th3 = tgo.create_thread(my_thread3);
+ boost::thread* res_tgo= tgo.join_first();
+ std::cout << "Algotithm " << res_tgo << " " << th2 << " finished the first with thread_group_once::join_first" << std::endl;
+
+
+ bith::thread_and_join_all(my_thread1, my_thread2, my_thread3);
+ std::cout << "All finished thread_and_join_all" << std::endl;
+
+ unsigned res = bith::thread_and_join_first_then_interrupt(my_thread1, my_thread2, my_thread3);
+ std::cout << "Algotithm " << res+1 << " finished the first with thread_and_join_first_then_interrupt" << std::endl;
+#endif
+
+ return 0;
+ }
+

Added: sandbox/interthreads/libs/interthreads/example/timestamped.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/example/timestamped.hpp 2008-11-19 10:54:11 EST (Wed, 19 Nov 2008)
@@ -0,0 +1,83 @@
+#ifndef BOOST_INTERTHREADS_TIMESTAMPED_HPP
+#define BOOST_INTERTHREADS_TIMESTAMPED_HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/thread/thread_time.hpp>
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include <boost/thread/thread.hpp>
+
+namespace boost {
+namespace interthreads {
+ template <typename T>
+ struct timestamped {
+#define XTIME
+#ifdef XTIME
+ boost::xtime date_;
+ void reset_date(unsigned seq) {
+ boost::xtime_get(&date_,1);
+ seq_ = seq;
+ }
+ struct ref_comparator {
+ typedef timestamped value_type;
+ bool operator()(const value_type&lhs, const value_type&rhs) {
+ if (lhs.date_.sec > rhs.date_.sec) return true;
+ else if (lhs.date_.sec == rhs.date_.sec && lhs.date_.nsec >= rhs.date_.nsec) return true;
+ else if (lhs.date_.nsec == rhs->date_.nsec && lhs.seq_ < rhs->seq_) return true;
+ return false;
+ }
+ };
+ struct ptr_comparator_gt {
+ typedef timestamped* value_type;
+ bool operator()(const value_type&lhs, const value_type&rhs) {
+ if (lhs->date_.sec > rhs->date_.sec) return true;
+ else if (lhs->date_.sec == rhs->date_.sec && lhs->date_.nsec > rhs->date_.nsec) return true;
+ else if (lhs->date_.nsec == rhs->date_.nsec && lhs->seq_ > rhs->seq_) return true;
+ return false;
+ }
+ };
+ struct ptr_comparator_lt {
+ typedef timestamped* value_type;
+ bool operator()(const value_type&lhs, const value_type&rhs) {
+ if (lhs->date_.sec < rhs->date_.sec) return true;
+ else if (lhs->date_.sec == rhs->date_.sec && lhs->date_.nsec < rhs->date_.nsec) return true;
+ else if (lhs->date_.nsec == rhs->date_.nsec && lhs->seq_ < rhs->seq_) return true;
+ return false;
+ }
+ };
+#else
+ system_time date_;
+ void reset_date(unsigned seq) {
+ date_ = system_time();
+ seq_ = seq;
+ }
+ struct ref_comparator {
+ typedef timestamped value_type;
+ bool operator()(const value_type&lhs, const value_type&rhs) {
+ return lhs.date_ >= rhs.date_;
+ }
+ };
+ struct ptr_comparator_gt {
+ typedef timestamped* value_type;
+ bool operator()(const value_type&lhs, const value_type&rhs) {
+ return (lhs->date_ > rhs->date_) ? true :
+ (lhs->date_ == rhs->date_) && (lhs->seq_ > rhs->seq_)? true:false;
+ }
+ };
+#endif
+ unsigned seq_;
+ T value_;
+ };
+}
+}
+
+
+#endif


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