美文网首页
DISPATCH_QUEUE_CONCURRENT(sync&

DISPATCH_QUEUE_CONCURRENT(sync&

作者: hope7th | 来源:发表于2016-03-13 20:44 被阅读97次

    dispatch_queue_t  serial =dispatch_queue_create("thedeeppacific",DISPATCH_QUEUE_CONCURRENT);

    dispatch_async(serial, ^{

    sleep(1);

    NSLog(@"4");

    });

    dispatch_sync(serial, ^{

    sleep(2);

    NSLog(@"9");

    });

    dispatch_async(serial, ^{

    sleep(1);

    NSLog(@"5");

    });

    dispatch_sync(serial, ^{

    sleep(1);

    NSLog(@"8");

    4,9,8,5

    在同步队列里逐个执行,在异步队列里同步执行。

    dispatch_queue_t  serial =dispatch_queue_create("thedeeppacific",DISPATCH_QUEUE_SERIAL);

    dispatch_sync(serial, ^{

    sleep(3);

    NSLog(@"1");

    });

    dispatch_async(serial, ^{

    sleep(4);

    NSLog(@"13");

    });

    dispatch_async(serial, ^{

    sleep(1);

    NSLog(@"11");

    });

    dispatch_sync(serial, ^{

    sleep(2);

    NSLog(@"2");

    });

    dispatch_sync(serial, ^{

    sleep(1);

    NSLog(@"3");

    });

    dispatch_async(serial, ^{

    sleep(3);

    NSLog(@"12");

    });

    1,13,11,2,3,12

    在一个进程里,无论同步异步,都是逐个执行

    相关文章

      网友评论

          本文标题: DISPATCH_QUEUE_CONCURRENT(sync&

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