Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1859] DispatchQueue setTarget fails with EXC_BAD_INSTRUCTION #741

Closed
swift-ci opened this issue Jun 21, 2016 · 7 comments
Closed

[SR-1859] DispatchQueue setTarget fails with EXC_BAD_INSTRUCTION #741

swift-ci opened this issue Jun 21, 2016 · 7 comments

Comments

@swift-ci
Copy link

Previous ID SR-1859
Radar None
Original Reporter Andreas Grosam (JIRA User)
Type Bug
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s libdispatch, Standard Library
Labels Bug, RunTimeCrash
Assignee Andreas Grosam (JIRA)
Priority Medium

md5: 731bcc2142f4e03e3ff0ffc5490a8cc6

Issue Description:

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:

func testSetTargetQueue() {
    let queue = DispatchQueue(label: "queue", attributes: DispatchQueueAttributes.serial)
    let syncQueue = 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"     
}
@belkadan
Copy link

cc mww (JIRA User)

@swift-ci
Copy link
Author

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
Copy link

Is there any point where it makes sense to call setTarget then? Should it just be hidden?

@swift-ci
Copy link
Author

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
Copy link
Author

Comment by Pierre Habouzit (JIRA)

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.

@swift-ci
Copy link
Author

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
Copy link
Author

Comment by Andreas Grosam (JIRA)

The new API and restrictions makes sense to me. Thanks for clearing this issue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants