iOS-Swift 信号量
let semaphore = DispatchSemaphore(value: 1) queue1.async { semaphore.wait() user.setName("1") print(user.name) semaphore.signal() } queue2.async { semaphore.wait() user.setName("2") print(user.name) semaphore.signal() }
let semaphore = DispatchSemaphore(value: 1) queue1.async { semaphore.wait() user.setName("1") print(user.name) semaphore.signal() } queue2.async { semaphore.wait() user.setName("2") print(user.name) semaphore.signal() }