Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Thread safety on group cancel #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions PSOperations/GroupOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ open class GroupOperation: Operation {
}
}

private let cancelLock = NSLock()

override open func cancel() {
internalQueue.cancelAllOperations()
internalQueue.isSuspended = false
super.cancel()
cancelLock.withCriticalScope {
internalQueue.cancelAllOperations()
internalQueue.isSuspended = false
super.cancel()
}
}

override open func execute() {
Expand Down Expand Up @@ -104,7 +108,9 @@ extension GroupOperation: OperationQueueDelegate {

if operation === finishingOperation {
internalQueue.isSuspended = true
finish(aggregatedErrors)
cancelLock.withCriticalScope {
finish(aggregatedErrors)
}
}
else if operation !== startingOperation {
operationDidFinish(operation, withErrors: errors)
Expand Down