Max values of semaphore?
问题 For example, there is a 1000 times loop. What's the max value to make it fast, effective, and not lead to a deadlock? let group = DispatchGroup() let queue = DispatchQueue(label: "com.num.loop", attributes: .concurrent) let semaphore = DispatchSemaphore(value: 4) for i in 1...1000 { semaphore.wait() group.enter() queue.async(group: group, execute: { doWork(i) group.leave() semaphore.signal() }) } group.notify(queue: DispatchQueue.main) { // go on... } 回答1: A couple of observations: You never