Skip to content

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

Closed

Description

@swift-ci
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"     
}

Activity

  1. belkadan commented on Jun 21, 2016

    @belkadan

    cc mww (JIRA User)

  2. swift-ci commented on Jun 21, 2016

    @swift-ci
    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.

  3. belkadan commented on Jun 21, 2016

    @belkadan

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

  4. swift-ci commented on Jun 21, 2016

    @swift-ci
    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().

  5. swift-ci commented on Jun 22, 2016

    @swift-ci
    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.

  6. swift-ci commented on Jun 22, 2016

    @swift-ci
    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.

  7. swift-ci commented on Jun 22, 2016

    @swift-ci
    Author

    Comment by Andreas Grosam (JIRA)

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

  8. transferred this issue fromswiftlang/swifton May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions