You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SR-1859] DispatchQueue setTarget fails with EXC_BAD_INSTRUCTION #741
With Swift 3, setting the target queue of an existing dispatch queue fails in the Simulator for iOS and tvOS. It does not fail on macOS. (watchOS not tested, and not tested on actual devices).
This did not fail with Swift 2.2.
The code below shows the issue:
functestSetTargetQueue() {
letqueue = DispatchQueue(label: "queue", attributes: DispatchQueueAttributes.serial)
letsyncQueue = DispatchQueue(label: "sync_queue", attributes: DispatchQueueAttributes.serial)
queue.setTarget(queue: syncQueue) // EXC_BAD_INSTRUCTION. Error: "Cannot change the target of this queue after it has been activated"
}
This is an intended behaviour change, DispatchQueue() accepts a ```queue:``` parameter for setting the target queue. After which the target queue hierarchy is immutable.
If you create a DispatchQueue with the .initiallyInactive flag then it's valid to call setTarget on it, it's similarly safe for sources pre-activate()/resume().
FWIW DispatchQueue.init() uses dispatch_queue_create_with_target() from the C interface, which documents this behavior extensively (in <dispatch/queue.h>). New APIs in Dispatch already enforce this behavior, and the Swift3 overlay is such a New API Surface.
Activity
belkadan commentedon Jun 21, 2016
cc mww (JIRA User)
swift-ci commentedon Jun 21, 2016
Comment by Matt Wright (JIRA)
This is an intended behaviour change, DispatchQueue() accepts a ```queue:``` parameter for setting the target queue. After which the target queue hierarchy is immutable.
belkadan commentedon Jun 21, 2016
Is there any point where it makes sense to call
setTargetthen? Should it just be hidden?swift-ci commentedon Jun 21, 2016
Comment by Matt Wright (JIRA)
If you create a DispatchQueue with the .initiallyInactive flag then it's valid to call setTarget on it, it's similarly safe for sources pre-activate()/resume().
swift-ci commentedon Jun 22, 2016
Comment by Pierre Habouzit (JIRA)
FWIW
DispatchQueue.init()usesdispatch_queue_create_with_target()from the C interface, which documents this behavior extensively (in<dispatch/queue.h>). New APIs in Dispatch already enforce this behavior, and the Swift3 overlay is such aNew API Surface.swift-ci commentedon Jun 22, 2016
Comment by Matt Wright (JIRA)
Closing given that this is both intended behaviour, and there is still a reason for DIspatchObject.setTarget(queue🙂 to exist.
swift-ci commentedon Jun 22, 2016
Comment by Andreas Grosam (JIRA)
The new API and restrictions makes sense to me. Thanks for clearing this issue.