3 ms·
Swift has easy access to pthread mutex and you can do that. serialQueue.async { // Critical section } is GCD's way of doing the same with the added benefit tha
by sovande 8y ago
Swift has easy access to pthread mutex and you can do that.
serialQueue.async { // Critical section } is GCD's way of doing the same with the added benefit that the calling code does not have to wait.
Problems in the parent code could be solved by using a mutex instead of GCD in this case. The code _has_ to wait for the access token to be loaded and not blocking does not make sense here unless you also introduce some kind of Promises.
- bunnycorn 8y agoThis. Also, GCD has DispatchSemaphore that is a Semaphore. Mutexes is a particular case of semaphores.