Github user tpcwang commented on a diff in the pull request:
https://github.com/apache/thrift/pull/980#discussion_r61601611
--- Diff: lib/cpp/src/thrift/concurrency/ThreadManager.cpp ---
@@ -421,7 +416,7 @@ void ThreadManager::Impl::removeWorker(size_t value) {
{
Synchronized s(workerMonitor_);
- while (workerCount_ != workerMaxCount_) {
+ while (workerCount_ > goalCount) {
--- End diff --
I had missed that it is using different monitors and thus different
mutexes. Thanks for clarifying.
I would still argue that this new implementation is worse than the existing
implementation. With the existing implementation, concurrent **writes** to
`workerMaxCount_` and `workerCount_` is synchronized, but the reading of those
values is not synchronized. Reading an aligned integer is most likely atomic on
most architectures, so this might not even be that unsafe (?). Getting either
the old value or the new value will not invalidate what it is trying to do.
On the other hand, the new implementation has a problem with concurrent
removeWorker and addWorker as far as I can tell. A removeWorker can be stuck
forever if a addWorker call comes in after the removeWorker sets the local
`goalCount` because it will never hit that goal with new workers that are
produced by addWorker.
Hopefully I didn't miss another detail. Thanks for working with me to
address these concerns.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---