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-2246] dispatchQueue.async(flags: .barrier) does not work #728

Closed
lilyball mannequin opened this issue Aug 1, 2016 · 4 comments
Closed

[SR-2246] dispatchQueue.async(flags: .barrier) does not work #728

lilyball mannequin opened this issue Aug 1, 2016 · 4 comments

Comments

@lilyball
Copy link
Mannequin

lilyball mannequin commented Aug 1, 2016

Previous ID SR-2246
Radar None
Original Reporter @lilyball
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 8 beta 4
Apple Swift version 3.0 (swiftlang-800.0.41.2 clang-800.0.36)
OS X 10.11.6 (15G31)

Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug, SDKOverlay
Assignee @lilyball
Priority Medium

md5: ff61bb039a743599a3c83b4cefb47e4d

Issue Description:

dispatchQueue.async(flags: .barrier, execute: …) does not work. When executed on a concurrent queue, it executes as a normal block instead of a barrier block.

Here's some code that reproduces the issue:

import Foundation

let timeout: Double = 5

class Test {
    var value = 0
    let queue = DispatchQueue(label: "test queue", attributes: .concurrent)

    func runTest() {
        let deadline = Date(timeIntervalSinceNow: timeout)

        DispatchQueue.global(qos: .userInitiated).async {
            while Date() < deadline {
                self.queue.async(flags: .barrier, execute: {
                    self.value = 1
                    Thread.sleep(forTimeInterval: 0.1)
                    self.value = 0
                })
                Thread.sleep(forTimeInterval: 0.01)
            }
        }

        while Date() < deadline {
            queue.sync {
                if self.value == 1 {
                    print("Barrier violation!")
                    exit(0)
                }
            }
        }
        print("deadline elapsed")
    }
}

Test().runTest()
@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 1, 2016

I think the problem is seen in the output of :type lookup __dispatch_async:

func __dispatch_async(_ queue: Dispatch.DispatchQueue, _ block: () -> Swift.Void)

Note how the block parameter does not have @convention(block).

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 1, 2016

Similarly dispatch_block_t is typed as () -> () instead of as @convention(block) () -> ().

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 2, 2016

Submitted as PR #3923.

@lilyball
Copy link
Mannequin Author

lilyball mannequin commented Aug 3, 2016

Merged in 5faa989.

I'm leaving this open until the next Xcode beta so I can confirm that the project I first diagnosed this with works (that project is tracking Xcode betas rather than swift snapshots).

@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

0 participants