Github user nsuke commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/1103#discussion_r81467452
  
    --- Diff: lib/cpp/src/thrift/concurrency/ThreadManager.cpp ---
    @@ -339,103 +357,88 @@ void ThreadManager::Impl::addWorker(size_t value) {
         idMap_.insert(std::pair<const Thread::id_t, shared_ptr<Thread> 
>((*ix)->getId(), *ix));
       }
     
    -  {
    -    Synchronized s(workerMonitor_);
    -    while (workerCount_ != workerMaxCount_) {
    -      workerMonitor_.wait();
    -    }
    +  while (workerCount_ != workerMaxCount_) {
    +    workerMonitor_.wait();
       }
     }
     
     void ThreadManager::Impl::start() {
    -
    +  Guard g(mutex_);
       if (state_ == ThreadManager::STOPPED) {
         return;
       }
     
    -  {
    -    Synchronized s(monitor_);
    -    if (state_ == ThreadManager::UNINITIALIZED) {
    -      if (!threadFactory_) {
    -        throw InvalidArgumentException();
    -      }
    -      state_ = ThreadManager::STARTED;
    -      monitor_.notifyAll();
    +  if (state_ == ThreadManager::UNINITIALIZED) {
    +    if (!threadFactory_) {
    +      throw InvalidArgumentException();
         }
    +    state_ = ThreadManager::STARTED;
    +    monitor_.notifyAll();
    +  }
     
    -    while (state_ == STARTING) {
    -      monitor_.wait();
    -    }
    +  while (state_ == STARTING) {
    +    monitor_.wait();
       }
     }
     
    -void ThreadManager::Impl::stopImpl(bool join) {
    +void ThreadManager::Impl::stop() {
    +  Guard g(mutex_);
       bool doStop = false;
    -  if (state_ == ThreadManager::STOPPED) {
    -    return;
    -  }
     
    -  {
    -    Synchronized s(monitor_);
    -    if (state_ != ThreadManager::STOPPING && state_ != 
ThreadManager::JOINING
    -        && state_ != ThreadManager::STOPPED) {
    -      doStop = true;
    -      state_ = join ? ThreadManager::JOINING : ThreadManager::STOPPING;
    -    }
    +  if (state_ != ThreadManager::STOPPING && state_ != ThreadManager::JOINING
    +      && state_ != ThreadManager::STOPPED) {
    +    doStop = true;
    +    state_ = ThreadManager::JOINING;
       }
     
       if (doStop) {
    -    removeWorker(workerCount_);
    +    removeWorkersUnderLock(workerCount_);
       }
     
    -  // XXX
    -  // should be able to block here for transition to STOPPED since we're no
    -  // using shared_ptrs
    -
    -  {
    -    Synchronized s(monitor_);
    -    state_ = ThreadManager::STOPPED;
    -  }
    +  state_ = ThreadManager::STOPPED;
     }
     
     void ThreadManager::Impl::removeWorker(size_t value) {
    -  std::set<shared_ptr<Thread> > removedThreads;
    -  {
    -    Synchronized s(monitor_);
    -    if (value > workerMaxCount_) {
    -      throw InvalidArgumentException();
    -    }
    +  Guard g(mutex_);
    +  removeWorkersUnderLock(value);
    +}
     
    -    workerMaxCount_ -= value;
    +void ThreadManager::Impl::removeWorkersUnderLock(size_t value) {
    +  if (value > workerMaxCount_) {
    +    throw InvalidArgumentException();
    +  }
     
    -    if (idleCount_ < value) {
    -      for (size_t ix = 0; ix < idleCount_; ix++) {
    -        monitor_.notify();
    -      }
    -    } else {
    -      monitor_.notifyAll();
    +  workerMaxCount_ -= value;
    +
    +  if (idleCount_ < value) {
    +    for (size_t ix = 0; ix < idleCount_; ix++) {
    --- End diff --
    
    I know it's not your code but shouldn't it be
    
        if (idleCount_ > value) {
            for( ...; ix < value; ...)
    
    ?
    If insufficient or equal number of people are sleeping, let's wake them up 
all, otherwise do it one by one.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to