$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r52828 - in sandbox/interthreads/libs/interthreads: build doc test
From: vicente.botet_at_[hidden]
Date: 2009-05-07 07:17:32
Author: viboes
Date: 2009-05-07 07:17:31 EDT (Thu, 07 May 2009)
New Revision: 52828
URL: http://svn.boost.org/trac/boost/changeset/52828
Log:
Boost.Interthreads V0.4.3 : Adaptation to Boost 1.39
Added:
   sandbox/interthreads/libs/interthreads/test/test_thread_shared_ptr.cpp   (contents, props changed)
Text files modified: 
   sandbox/interthreads/libs/interthreads/build/Jamfile.v2 |    12 +++++-------                            
   sandbox/interthreads/libs/interthreads/doc/changes.qbk  |     3 +++                                     
   sandbox/interthreads/libs/interthreads/test/Jamfile.v2  |    13 ++++++-------                           
   3 files changed, 14 insertions(+), 14 deletions(-)
Modified: sandbox/interthreads/libs/interthreads/build/Jamfile.v2
==============================================================================
--- sandbox/interthreads/libs/interthreads/build/Jamfile.v2	(original)
+++ sandbox/interthreads/libs/interthreads/build/Jamfile.v2	2009-05-07 07:17:31 EDT (Thu, 07 May 2009)
@@ -42,16 +42,16 @@
         <threading>multi
 #       <target-os>cygwin
 #       <interthreadapi>pthread
-        <variant>debug
+#        <variant>debug
 #       <define>BOOST_THREAD_HAS_THREAD_ATTR
     
       <include>../../..
-      <include>../../../../../boost_1_38_0
+      <include>/boost_1_39_0
       <link>static:<define>BOOST_INTERTHREADS_BUILD_LIB=1
       <link>shared:<define>BOOST_INTERTHREADS_BUILD_DLL=1 
 #      <link>shared:<library>/boost/thread//boost_thread/<link>shared
-      -<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
-      <tag>@$(__name__).tag
+#      -<tag>@$(BOOST_JAMROOT_MODULE)%$(BOOST_JAMROOT_MODULE).tag
+#      <tag>@$(__name__).tag
 #      <library>$(BOOST_ROOT)/libs/thread/build//boost_thread/<link>shared
     : default-build <threading>multi
     ;
@@ -204,13 +204,11 @@
 
 
 static-lib boost_interthreads
-    : thread_decorator.cpp  thread_keep_alive.cpp interthreads_sources
-#    ../../../../libs/thread/build//boost_thread
+    : thread_decorator.cpp  thread_keep_alive.cpp #interthreads_sources
     : <conditional>@requirements
     :
     : <link>shared:<define>BOOST_INTERTHREADS_USE_DLL=1
       <link>static:<define>BOOST_INTERTHREADS_USE_LIB=1
-#      <link>static:<library>/boost/thread//boost_thread/<link>static
       <conditional>@usage-requirements
             
     ;
Modified: sandbox/interthreads/libs/interthreads/doc/changes.qbk
==============================================================================
--- sandbox/interthreads/libs/interthreads/doc/changes.qbk	(original)
+++ sandbox/interthreads/libs/interthreads/doc/changes.qbk	2009-05-07 07:17:31 EDT (Thu, 07 May 2009)
@@ -7,6 +7,9 @@
 
 [section:changes  Appendix A: History]
 
+[section [*Version 0.4.3, May 9, 2009] Adaptation to Boost 1.39
+[endsect]
+
 [section [*Version 0.4.2, Mars 9, 2009] Adaptation to the Boost.ThreadPoold Version 0.23]
 
 [*New Features:]
Modified: sandbox/interthreads/libs/interthreads/test/Jamfile.v2
==============================================================================
--- sandbox/interthreads/libs/interthreads/test/Jamfile.v2	(original)
+++ sandbox/interthreads/libs/interthreads/test/Jamfile.v2	2009-05-07 07:17:31 EDT (Thu, 07 May 2009)
@@ -23,18 +23,17 @@
     : requirements
 #       <library>/boost/test//boost_unit_test_framework/<link>static
 #       <library>/boost/thread//boost_thread/<link>static
-        <library>../../../../../boost_1_38_0/libs/test/build//boost_unit_test_framework/<link>static
-        <library>../build//boost_interthreads/<link>static
-#        <library>../../tp/build//boost_threadpool/<link>static
-        <library>../../../../../boost_1_38_0/libs/thread/build//boost_thread/<link>static
+        <library>/boost_1_39_0/libs/test/build//boost_unit_test_framework/<link>static
+        <library>/boost_1_39_0/libs/thread/build//boost_thread/<link>static
+        #<library>../build//boost_interthreads/<link>static
 
         <include>.
         <include>../../..
-        <include>../../../../../boost_1_38_0
+        <include>/boost_1_39_0
         <threading>multi
 #       <target-os>cygwin
 #       <interthreadapi>pthread
-        <variant>debug
+#        <variant>debug
 #       <define>BOOST_THREAD_HAS_THREAD_ATTR
 
     ;
@@ -42,7 +41,7 @@
 rule interthreads-run ( sources * )
 {
     return
-    [ run $(sources)  :  :  : <link>static ]
+    [ run $(sources)  ../build//boost_interthreads :  :  : <link>static ]
 #    [ run $(sources)  ../../../../libs/thread/build//boost_thread  :  :  :              : $(sources[1]:B)_lib ]
     ;
 }
Added: sandbox/interthreads/libs/interthreads/test/test_thread_shared_ptr.cpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/libs/interthreads/test/test_thread_shared_ptr.cpp	2009-05-07 07:17:31 EDT (Thu, 07 May 2009)
@@ -0,0 +1,159 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-2009.
+// 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>
+boost::mutex out_global_mutex;
+#include <boost/thread/locks.hpp>
+#include <boost/thread.hpp>
+#include <iostream>
+#include <boost/interthreads/thread_specific_shared_ptr.hpp>
+#include <boost/interthreads/thread_decorator.hpp>
+
+void sleep(int sec)
+{
+    boost::xtime t;
+    boost::xtime_get(&t,1); t.sec += sec; boost::thread::sleep(t);
+}
+
+// A state class living in shared memory.
+// The class must have its own sync mechanism.
+class state {
+public:
+    state() : result(0)
+    {}
+    void set_result(int n)
+    {
+        boost::mutex::scoped_lock lock(monitor);
+        result = n;
+    }
+    int get_result()
+    {
+        boost::mutex::scoped_lock lock(monitor);
+        return result;
+    }
+    static void deleter(state * p) { delete p; }
+private:
+    ~state() {}
+    boost::mutex monitor;
+    int result;
+};
+
+// The conventional tss pointer.
+// It can be seen as a memory space that is
+// only privately accessible by the thread,
+// when interpreted in our context.
+boost::thread_specific_ptr<int> private_int;
+
+// The thread member pointer.
+// Its syntax is almost the same when used
+// from "inside" a thread as that of the
+// thread_specific_ptr. I named it public
+// to underpin the fact it is accessible
+// from "outside" too. (Perhaps other names
+// than thread_specific_shared_ptr and thread_specific_ptr
+// would be more appropriate? Any suggestions?
+// E.g. thread_public_ptr and thread_private_ptr?)
+boost::interthreads::thread_specific_shared_ptr<state> public_state;
+
+// It might be convenient to have a function
+// that is called automatically on thread start
+// up to auto initialize the variables.
+void init_state_fn()
+{
+    {
+        boost::mutex::scoped_lock out_guard(out_global_mutex);
+        std::cout << "init_state_fn" << " " << boost::this_thread::get_id()<<std::endl;
+    }
+
+    public_state.reset(new state(), state::deleter);
+    private_int.reset(new int(0));
+}
+
+boost::interthreads::thread_decoration init_state(init_state_fn);
+
+
+void run()
+{
+    init_state_fn();
+    sleep(2);
+    {
+        boost::mutex::scoped_lock out_guard(out_global_mutex);
+        std::cout << "run " << " " << boost::this_thread::get_id()<<std::endl;
+    }
+    public_state->set_result(42);
+
+    boost::shared_ptr<state> ths = public_state[boost::this_thread::get_id()];
+    int result;
+    result = ths->get_result();
+    {
+        boost::mutex::scoped_lock out_guard(out_global_mutex);
+        std::cout << "ahead " << result << " " << boost::this_thread::get_id()<<std::endl;
+    }
+    sleep(2);
+
+}
+
+int main(int argc, char* argv[])
+{
+    int result;
+
+    boost::thread* th = new boost::thread(boost::interthreads::make_decorator(run));
+
+    const boost::shared_ptr<state> ths = public_state.wait_and_get(th->get_id());
+    if (ths.get()!=0) {
+        result = ths->get_result();
+        {
+            boost::mutex::scoped_lock out_guard(out_global_mutex);
+            std::cout << "ahead " << result << " " << boost::this_thread::get_id()<<std::endl;
+        }
+    }
+
+    private_int.reset(new int(0));
+    ths->set_result(1111);
+    if (ths.get()!=0) {
+        result = ths->get_result();
+        {
+            boost::mutex::scoped_lock out_guard(out_global_mutex);
+            std::cout << "ahead " << result << " " << boost::this_thread::get_id()<<std::endl;
+        }
+    }
+
+    sleep(2);
+    boost::shared_ptr<state> ths3 = public_state[th->get_id()];
+    if (ths.get()!=0) {
+        result = ths->get_result();
+        {
+            boost::mutex::scoped_lock out_guard(out_global_mutex);
+            std::cout << "ahead " << result << " " << boost::this_thread::get_id()<<std::endl;
+        }
+    }
+
+    th->join();
+
+    delete th;
+
+    // We still may access the state object by means of the shared_ptr.
+    if (ths.get()!=0) {
+        result = ths->get_result();
+        {
+            boost::mutex::scoped_lock out_guard(out_global_mutex);
+            std::cout << "ahead " << result << " " << boost::this_thread::get_id()<<std::endl;
+        }
+    }
+    const boost::shared_ptr<state> cths(new state(), state::deleter);
+    cths->set_result(2);
+    {
+        boost::mutex::scoped_lock out_guard(out_global_mutex);
+        std::cout << "xxx" << cths->get_result() << " " << boost::this_thread::get_id()<<std::endl;
+    }
+    return 0;
+}
+