闲话少说直接上代码
dispatch_queue_t queueA = dispatch_queue_create("com.effectiveobjective.queueA", NULL);
dispatch_queue_t queueB = dispatch_queue_create("com.effectiveobjective.queueB", NUL);
dispatch_set_target_queue(queueB, queueA);
static int kQueueSpecific;
CFStringRef queueSpecificValue = CFSTR("queueA");
dispatch_queue_set_specific(queueA, //
&kQueueSpecific, //key
(void *)queueSpecificValue, //value
(dispatch_function_t)CFRelease);
dispatch_sync(queueB, ^{
dispatch_block_t block = ^{
NSLog(@"No deadLock!");
};
CFStringRef retrieveValue = dispatch_get_specific(&kQueueSpecific);
if(retrievedValue){
block;
}else{
dispatch_queue(queueA, block);
}
});
网友评论