You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2012/05/17 06:32:11 UTC

svn commit: r1339477 - /thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp

Author: jfarrell
Date: Thu May 17 04:32:10 2012
New Revision: 1339477

URL: http://svn.apache.org/viewvc?rev=1339477&view=rev
Log:
Thrift-1606:Race condition in BoostThreadFactory.cpp
Client: cpp
Patch: alexandre parenteau

Race condition between the line that set state_ to "starting", and the line that checked to make sure that it was "starting". That ended meaning that sometimes calling "start()" would not result in the thread's runnable being called.


Modified:
    thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp

Modified: thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp?rev=1339477&r1=1339476&r2=1339477&view=diff
==============================================================================
--- thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp (original)
+++ thrift/trunk/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp Thu May 17 04:32:10 2012
@@ -60,10 +60,10 @@ class BoostThread: public Thread {
  public:
 
   BoostThread(bool detached, shared_ptr<Runnable> runnable) :
-	 state_(uninitialized),
-	 detached_(detached) {
-    this->Thread::runnable(runnable);
-  }
+    state_(uninitialized),
+    detached_(detached) {
+      this->Thread::runnable(runnable);
+    }
 
   ~BoostThread() {
     if(!detached_) {
@@ -79,27 +79,27 @@ class BoostThread: public Thread {
     if (state_ != uninitialized) {
       return;
     }
-	
-	// Create reference
+  
+  // Create reference
     shared_ptr<BoostThread>* selfRef = new shared_ptr<BoostThread>();
     *selfRef = self_.lock();
 
-	thread_ = std::auto_ptr<boost::thread>(new boost::thread(boost::bind(threadMain, (void*)selfRef)));
+    state_ = starting;
 
-	if(detached_)
-		thread_->detach();
+    thread_ = std::auto_ptr<boost::thread>(new boost::thread(boost::bind(threadMain, (void*)selfRef)));
 
-	state_ = starting;
+    if(detached_)
+      thread_->detach();
   }
 
   void join() {
     if (!detached_ && state_ != uninitialized) {
-	  thread_->join();
+      thread_->join();
     }
   }
 
   Thread::id_t getId() {
-	  return thread_.get() ? thread_->get_id() : boost::thread::id();
+    return thread_.get() ? thread_->get_id() : boost::thread::id();
   }
 
   shared_ptr<Runnable> runnable() const { return Thread::runnable(); }
@@ -163,9 +163,8 @@ class BoostThreadFactory::Impl {
   void setDetached(bool value) { detached_ = value; }
 
   Thread::id_t getCurrentThreadId() const {
-	  return boost::this_thread::get_id();
+    return boost::this_thread::get_id();
   }
-
 };
 
 BoostThreadFactory::BoostThreadFactory(bool detached) :