You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King, III (JIRA)" <ji...@apache.org> on 2017/02/19 02:27:44 UTC
[jira] [Resolved] (THRIFT-4004) ThreadManager deadlock when adding
new task
[ https://issues.apache.org/jira/browse/THRIFT-4004?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James E. King, III resolved THRIFT-4004.
----------------------------------------
Resolution: Invalid
Fix Version/s: 0.10.0
In the scenario you described, there would not be a deadlock.
Task #1 is added and monitor_ is signaled.
The worker does not wake up.
Task #2 inside add() would call maxMonitor_.wait() - this unlocks the mutex, since all of the monitors are sharing the same mutex.
The worker wakes up from waiting on monitor_ because it can acquire the mutex. It pops something off the queue. Then it sees the queue is less than the maximum so it signals maxMonitor_. Then it unlocks the mutex to run the task.
The add() for Task #2 would wake up from maxMonitor_ and add the task.
What makes this safe today as compared to past versions is that all three monitors share the same mutex.
> ThreadManager deadlock when adding new task
> -------------------------------------------
>
> Key: THRIFT-4004
> URL: https://issues.apache.org/jira/browse/THRIFT-4004
> Project: Thrift
> Issue Type: Bug
> Components: C++ - Library
> Affects Versions: 0.9.3
> Reporter: Liu Lin
> Assignee: James E. King, III
> Fix For: 0.10.0
>
>
> Set pendingTaskCountMax = 1.
> Add only 1 worker into ThreadManager.
> When adding task, set timeout > 0.
> If there is no task, worker thread will sleep, because manager_->monitor_.wait(Line 259) is called in function ThreadManager::Worker::run.
> Then suppose we have 2 tasks. We add the first task by calling ThreadManager::Impl::add, which will nofity monitor_. But before manager_->monitor_.wait() returns, we call ThreadManager::Impl::add again. If ThreadManager::Impl::add gets lock mutex_ successfully, ThreadManager::Worker::run will fall asleep again because it can not lock mutex_.
> Now we have tasks_.size() == pendingTaskCountMax_, so ThreadManager::Impl::add will wait on maxMonitor_(Line 462). Becasue the worker cannot fetch a task(because it can not lock mutex_, it will not notify maxMonitor_), so ThreadManager::Impl::add will wait forever.
> Now both the two threads wait for each other, result in deadlock.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)