[英]How to test at runtime if a block is currently executed on the main queue?
I am using an API where it is not entirely clear if the block is always executed on the main queue. 我使用的API尚不清楚,该块是否总是在主队列上执行。 If it is not, then I need to call the main queue synchronously.
如果不是,那么我需要同步调用主队列。
How can I check if the block is already executing on the main queue? 如何检查该块是否已在主队列上执行?
dispatch_get_current_queue()
is deprecated. dispatch_get_current_queue()
已弃用。 Must I use dispatch_get_specific()
to get an comparable identifier? 我是否必须使用
dispatch_get_specific()
获得可比较的标识符?
The unique thing about the main queue is that it is always matched exactly to the main thread. 关于主队列的独特之处在于,它始终与主线程完全匹配。 So you can use
[NSThread isMainThread]
. 因此,您可以使用
[NSThread isMainThread]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.