美文网首页
iOS开发之获得当前线程

iOS开发之获得当前线程

作者: 孙健会员 | 来源:发表于2017-05-24 11:18 被阅读3302次

    闲话少说直接上代码

    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);
        }
    });
    
    

    相关文章

      网友评论

          本文标题:iOS开发之获得当前线程

          本文链接:https://www.haomeiwen.com/subject/atzcxxtx.html