什么是Swift相当于Objective-C的“@ synchronized”? [英] What is the Swift equivalent to Objective-C's "@synchronized"?
本文介绍了什么是Swift相当于Objective-C的“@ synchronized”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索了Swift的书,但找不到Swift版本的@synchronized。如何在Swift中实现互斥?
I've searched the Swift book, but can't find the Swift version of @synchronized. How do I do mutual exclusion in Swift?
推荐答案
我使用GCD。它比 @synchronized
稍微冗长一点,但是作为替代品工作得很好:
I'm using GCD. It's a little more verbose than @synchronized
, but works perfectly well as a replacement:
let lockQueue = dispatch_queue_create("com.test.LockQueue", nil)
dispatch_sync(lockQueue) {
// code
}
这篇关于什么是Swift相当于Objective-C的“@ synchronized”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文