Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-04-14 17:04:33


Author: anthonyw
Date: 2008-04-14 17:04:33 EDT (Mon, 14 Apr 2008)
New Revision: 44424
URL: http://svn.boost.org/trac/boost/changeset/44424

Log:
Fix for issue #1657
Text files modified:
   trunk/libs/thread/example/condition.cpp | 12 ++++++++++--
   1 files changed, 10 insertions(+), 2 deletions(-)

Modified: trunk/libs/thread/example/condition.cpp
==============================================================================
--- trunk/libs/thread/example/condition.cpp (original)
+++ trunk/libs/thread/example/condition.cpp 2008-04-14 17:04:33 EDT (Mon, 14 Apr 2008)
@@ -46,11 +46,16 @@
 
 bounded_buffer buf(2);
 
+boost::mutex io_mutex;
+
 void sender() {
     int n = 0;
     while (n < 100) {
         buf.send(n);
- std::cout << "sent: " << n << std::endl;
+ {
+ boost::mutex::scoped_lock io_lock(io_mutex);
+ std::cout << "sent: " << n << std::endl;
+ }
         ++n;
     }
     buf.send(-1);
@@ -60,7 +65,10 @@
     int n;
     do {
         n = buf.receive();
- std::cout << "received: " << n << std::endl;
+ {
+ boost::mutex::scoped_lock io_lock(io_mutex);
+ std::cout << "received: " << n << std::endl;
+ }
     } while (n != -1); // -1 indicates end of buffer
 }
 


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