标签:ase val get ecif ref 方便 int something com
有时候我们很希望知道当前执行的queue是谁,比如UI操作需要放在main queue中执行。如果可以知道当前工作的queue是谁,就可以很方便的指定一段代码操作在特定的queue中执行。这种做法让GCD方法达到可重入效果:
dispatch_queue_set_specific 标记队列
static int specificKey;
CFStringRef specificValue = CFSTR("queueA");
dispatch_queue_set_specific(queueA,
&specificKey,
(void*)specificValue,
(dispatch_function_t)CFRelease);
dispatch_sync(queueB, ^{
dispatch_block_t block = ^{
//do something
};
CFStringRef retrievedValue = dispatch_get_specific(&specificKey);
if (retrievedValue) {
block();
} else {
dispatch_sync(queueA, block);
}
});
dispatch_queue_set_specific可重入的gcd
标签:ase val get ecif ref 方便 int something com
原文地址:https://www.cnblogs.com/diyigechengxu/p/9213171.html