美文网首页
我在这里等你(GCD)

我在这里等你(GCD)

作者: Alienchang | 来源:发表于2016-11-04 19:02 被阅读26次
    BOOL ifYouBack = false;
    
    - (void)waitForYou{
        dispatch_queue_t ourLifeQueue = dispatch_get_main_queue(); 
    //    dispatch_queue_t waitForYouQueue =      dispatch_queue_create("I.AM.ALWAYS.HERE", DISPATCH_QUEUE_CONCURRENT);
        dispatch_queue_t waitForYouQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
        dispatch_async(waitForYouQueue, ^{
            while (![self ifYouback]) {
                dispatch_sync(ourLifeQueue, ^{
                    NSLog(@"let's begin a happy life, 115-110-111-119");
                });
            }
        });
        
        while (![self ifYouback]) {
            sleep(1);
            dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                while (![self ifYouback]) {
                    NSLog(@"do some thing for life");
                }
            });
        } 
    }
    
    - (BOOL)ifYouback{
        return ifYouBack;
    }
    

    相关文章

      网友评论

          本文标题:我在这里等你(GCD)

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