[SR-11854] OperationQueue not asynchronous
swift-ci opened this issue · comments
Previous ID | SR-11854 |
Radar | rdar://problem/57549294 |
Original Reporter | ZakMcK (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
Environment
Swift Runtime
Swift version 5.1 (swift-5.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
OS
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation, libdispatch |
Labels | Bug |
Assignee | @lxbndr |
Priority | Medium |
md5: 7ac99bf05c7d6c768f6910f21d555ebb
Issue Description:
I have a problem with the OperationQueue in the swift-5.1.2-RELEASE version. The whole OperationQueue seems to work synchronously with one single thread instead of using all available cores.
This worked with swift 5.0. Following example
let testQueue = OperationQueue()
testQueue.name = "TestAsync"
testQueue.maxConcurrentOperationCount = 4
for _ in 0...10 {
testQueue.addOperation {
print("added \(Thread.current) on \(OperationQueue.current?.underlyingQueue?.label ?? "None")")
//Thread.sleep(forTimeInterval: 1)
}
//print("OP COUNT: \(testQueue.operationCount)")
}
testQueue.waitUntilAllOperationsAreFinished()
yields this output
Hello, world!
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
OP COUNT: 1
done pushing operations
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
added <Thread: 0x00007f8e14000c80> on None
I would assume that different threads should be incorporated (maxConcurrentOperationCount is set to 4).
@swift-ci create