fix potential deadlock in BlockingIOThreadPool (#634)

Motivation:

BlockingIOThreadPool used to call out with a lock held and on top of
that on the wrong thread...

Modifications:

Make BlockingIOThreadPool call out on the supplied `queue`

Result:

fewer deadlock and surprises
This commit is contained in:
Johannes Weiss authored and GitHub committed 2018-10-19 16:52:51 +01:00
1 parent 9bae007a15
commit 176dd6e856
3 files changed
+84 -2

No files matched your search

+4 -2
View File
@@ -68,7 +68,9 @@ public final class BlockingIOThreadPool {
self.lock.withLock {
switch self.state {
case .running(let items):
items.forEach { $0(.cancelled) }
queue.async {
items.forEach { $0(.cancelled) }
}
self.state = .shuttingDown(Array(repeating: true, count: numberOfThreads))
(0..<numberOfThreads).forEach { _ in
self.semaphore.signal()
@@ -162,7 +164,7 @@ public final class BlockingIOThreadPool {
self.queues.enumerated().forEach { idAndQueue in
let id = idAndQueue.0
let q = idAndQueue.1
q.async { [unowned self] in
q.async {
self.process(identifier: id)
}
}