Skip to content

Commit

Permalink
BackgroundTask : Remove deadlock mitigation
Browse files Browse the repository at this point in the history
But keep detection, so in the unlikely event this happens we can prompt the user to provide a useful bug report.
  • Loading branch information
johnhaddon committed Jun 12, 2024
1 parent 2f36757 commit 3d8dd6f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
19 changes: 0 additions & 19 deletions python/GafferTest/BackgroundTaskTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,5 @@ def f( canceller ) :
# check for cancellation, and we'll deadlock.
del task

def testSelfWait( self ) :

def f( canceller ) :
# It makes zero sense for a task to wait for itself. Rather than
# allow it to deadlock, we want to emit a diagnostic message and
# continue.
task.wait()

mh = IECore.CapturingMessageHandler()
IECore.MessageHandler.setDefaultHandler( mh )

task = Gaffer.BackgroundTask( None, f )
task.wait()

self.assertEqual( len( mh.messages ), 1 )
self.assertEqual( mh.messages[0].level, IECore.Msg.Level.Error )
self.assertEqual( mh.messages[0].context, "BackgroundTask::wait" )
self.assertEqual( mh.messages[0].message, "Task attempted to wait for itself" )

if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions src/Gaffer/BackgroundTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ void BackgroundTask::wait()
std::unique_lock<std::mutex> lock( m_taskData->mutex );
if( m_taskData->threadId == std::this_thread::get_id() )
{
IECore::msg( IECore::Msg::Error, "BackgroundTask::wait", "Task attempted to wait for itself" );
return;
IECore::msg( IECore::Msg::Error, "BackgroundTask::wait", "Deadlock detected : Task is attempting to wait for itself. Please provide stack trace in bug report." );
}

m_taskData->conditionVariable.wait(
Expand Down

0 comments on commit 3d8dd6f

Please sign in to comment.