Navigation Menu

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-5759] DispatchSources should be independently cancellable #682

Closed
weissi opened this issue Aug 24, 2017 · 1 comment
Closed

[SR-5759] DispatchSources should be independently cancellable #682

weissi opened this issue Aug 24, 2017 · 1 comment

Comments

@weissi
Copy link
Member

weissi commented Aug 24, 2017

Previous ID SR-5759
Radar None
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug, Linux
Assignee phabouzit (JIRA)
Priority Medium

md5: ce6f2127d12f4b5b86ad03472c82a552

Issue Description:

DispatchSources should be independently cancellable.

In other words, when compiling this program

import Dispatch

func makeSource(fd: Int32, queue: DispatchQueue, handler: DispatchWorkItem) -> DispatchSourceRead {
    let s = DispatchSource.makeReadSource(fileDescriptor: Int32(fd), queue: queue)
    s.setEventHandler(handler: handler)
    s.resume()
    return s
}

let q = DispatchQueue(label: "some q", attributes: .concurrent)
let numFakeSources = 32
var fakeSources: [DispatchSourceRead] = []
let fd: Int32 = 0
let sem = DispatchSemaphore(value: 0)

for f in 0..<numFakeSources {
    fakeSources.append(makeSource(fd: fd, queue: q, handler: DispatchWorkItem(block: {
        print("fake source A \(f) fired")
    })))
}

let realSource = makeSource(fd: fd, queue: q, handler: DispatchWorkItem(block: {
    print("real source fired")
    sem.signal()
}))

for f in 0..<numFakeSources {
    fakeSources.append(makeSource(fd: fd, queue: q, handler: DispatchWorkItem(block: {
        print("fake source B \(f) fired")
    })))
}

_ = fakeSources.map { $0.cancel() }

sem.wait()

and running it as

for f in $(seq 100); do cat /dev/null | ./test; done

it should not hang. That's true on Darwin but not on Linux. I showed this to phabouzit (JIRA User) and he found the bug and is working on a patch. Filing because I'll be on holiday from tomorrow and want to finish the work after I'm back.

The bug described in SR-4567 is pretty certainly this bug too.

@swift-ci
Copy link

swift-ci commented Sep 4, 2017

Comment by Pierre Habouzit (JIRA)

#295 merged in master & swift-4

@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