Skip to content

Commit 1f9d6a6

Browse files
authored
resolve inserting operations as a batch race to the execution of operations (#621)
1 parent 7868123 commit 1f9d6a6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Foundation/NSOperation.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,13 @@ open class OperationQueue: NSObject {
399399
execution. The only differential is that the block enqueued to dispatch_async
400400
is balanced with the number of Operations enqueued to the NSOperationQueue.
401401
*/
402+
lock.lock()
402403
ops.forEach { (operation: Operation) -> Void in
403-
lock.lock()
404404
operation._queue = self
405405
_operations.insert(operation)
406-
lock.unlock()
406+
}
407+
lock.unlock()
408+
ops.forEach { (operation: Operation) -> Void in
407409
#if DEPLOYMENT_ENABLE_LIBDISPATCH
408410
if let group = waitGroup {
409411
group.enter()

0 commit comments

Comments
 (0)