Skip to content

Commit

Permalink
JobQueue deadlocks
Browse files Browse the repository at this point in the history
Problem
-------

The JobQueue holds the lock while executing jobs.  A job must be free
to acquire any lock including the JobQueue lock to avoid deadlocks.

Solution
--------

Release the lock before executing jobs.
  • Loading branch information
jrw972 committed Jan 31, 2025
1 parent b20c1a9 commit 9e0233b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dds/DCPS/JobQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ int JobQueue::handle_exception(ACE_HANDLE /*fd*/)
ThreadStatusManager::Event ev(thread_status_manager);

Queue q;
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, -1);
q.swap(job_queue_);
}

ACE_Reverse_Lock<ACE_Thread_Mutex> rev_lock(mutex_);
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, -1);
q.swap(job_queue_);
for (Queue::const_iterator pos = q.begin(), limit = q.end(); pos != limit; ++pos) {
ThreadStatusManager::Event event(thread_status_manager);
(*pos)->execute();
}

ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, -1);
if (!job_queue_.empty()) {
guard.release();
reactor()->notify(this);
Expand Down

0 comments on commit 9e0233b

Please sign in to comment.