Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4004

ThreadManager deadlock when adding new task

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 0.9.3
    • 0.10.0
    • C++ - Library
    • None

    Description

      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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jking3 James E. King III
            liulin Liu Lin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment