Closed
Description
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.