3 ms·
let mutex = DispatchQueue(label: “”) mutex.sync { /* protected code here */ } As for @sychronized, the devs have talked about why it is flawed (requires do
by gilgoomesh 9y ago
let mutex = DispatchQueue(label: “”)
mutex.sync { /* protected code here */ }
As for @sychronized, the devs have talked about why it is flawed (requires double locking) and why use should always use a manual mutex scope.
- bsaul 9y agoCreating a closure and scheduling it on a queue seems like a pretty heavyweight way to ensure exclusive access (see https://www.cocoawithlove.com/blog/2016/06/02/threads-and-mutexes.html#mutexes-and-closure-capture-pitfalls https://www.cocoawithlove.com/blog/2016/06/02/threads-and-mu... for more). EDIT: aren't you the one that wrote this article ? :))