Fix for Deadlock in NSOperationQueue #49: If an exception occurs when trying to detach thread, catch it and log it so that locking is not broken by the exception breaking out of the lock protected region.

This commit is contained in:
Richard Frith-Macdonald 2020-04-16 22:48:25 +01:00
parent 6ee0cfff00
commit 6d714c8ee1

View file

@ -1100,9 +1100,18 @@ static NSOperationQueue *mainQueue = nil;
|| (pending > 0 && internal->threadCount < POOL))
{
internal->threadCount++;
[NSThread detachNewThreadSelector: @selector(_thread)
toTarget: self
withObject: nil];
NS_DURING
{
[NSThread detachNewThreadSelector: @selector(_thread)
toTarget: self
withObject: nil];
}
NS_HANDLER
{
NSLog(@"Failed to create thread for %@: %@",
self, localException);
}
NS_ENDHANDLER
}
/* Tell the thread pool that there is an operation to start.
*/