Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82392 - in trunk: boost/thread libs/thread/example
From: vicente.botet_at_[hidden]
Date: 2013-01-07 18:13:43


Author: viboes
Date: 2013-01-07 18:13:43 EST (Mon, 07 Jan 2013)
New Revision: 82392
URL: http://svn.boost.org/trac/boost/changeset/82392

Log:
Thread: improve external lock for externally_locked_stream.
Text files modified:
   trunk/boost/thread/externally_locked_stream.hpp | 17 ++++++++++++-----
   trunk/libs/thread/example/not_interleaved.cpp | 9 +++++++--
   2 files changed, 19 insertions(+), 7 deletions(-)

Modified: trunk/boost/thread/externally_locked_stream.hpp
==============================================================================
--- trunk/boost/thread/externally_locked_stream.hpp (original)
+++ trunk/boost/thread/externally_locked_stream.hpp 2013-01-07 18:13:43 EST (Mon, 07 Jan 2013)
@@ -14,6 +14,7 @@
 #include <boost/thread/externally_locked.hpp>
 #include <boost/thread/lock_traits.hpp>
 #include <boost/thread/recursive_mutex.hpp>
+#include <boost/thread/strict_lock.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -32,11 +33,6 @@
   template <class Stream>
   class stream_guard
   {
- stream_guard(externally_locked_stream<Stream>& mtx, adopt_lock_t) :
- mtx_(mtx)
- {
- }
-
 
     friend class externally_locked_stream<Stream> ;
   public:
@@ -50,6 +46,11 @@
       mtx.lock();
     }
 
+ stream_guard(externally_locked_stream<Stream>& mtx, adopt_lock_t) :
+ mtx_(&mtx)
+ {
+ }
+
     stream_guard(BOOST_THREAD_RV_REF(stream_guard) rhs)
     : mtx_(rhs.mtx_)
     {
@@ -107,6 +108,12 @@
       return stream_guard<Stream> (*this);
     }
 
+ Stream& hold(strict_lock<recursive_mutex>& lk)
+ {
+ return this->get(lk);
+ }
+
+
   };
   //]
 

Modified: trunk/libs/thread/example/not_interleaved.cpp
==============================================================================
--- trunk/libs/thread/example/not_interleaved.cpp (original)
+++ trunk/libs/thread/example/not_interleaved.cpp 2013-01-07 18:13:43 EST (Mon, 07 Jan 2013)
@@ -48,8 +48,13 @@
   scoped_thread<> t2(thread(use_cout, boost::ref(mcout)));
   this_thread::sleep_for(chrono::seconds(2));
   std::string nm;
- mcout << "Enter name: ";
- //mcin >> nm;
+ {
+ strict_lock<recursive_mutex> lk(terminal_mutex);
+ auto& gcout = mcout.hold(lk);
+ auto& gcin = mcin.hold(lk);
+ gcout << "Enter name: ";
+ //gcin >> nm;
+ }
   t1.join();
   mcout << nm << '\n';
   return 1;


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