多线程 GCD 异步同步与串行

2020-05-25  本文已影响0人  f75dfaf80e43

请教多线程 GCD 关于异步同步与串行相关的问题

```

dispatch_queue_t queue = dispatch_queue_create("com.serial.com", DISPATCH_QUEUE_SERIAL);

    NSLog(@"1-%@",[NSThread currentThread]);

    dispatch_async(queue,^ {

        NSLog(@"2-%@",[NSThread currentThread]);

        dispatch_sync(queue,^{

            NSLog(@"3-%@",[NSThread currentThread]);

        });

        NSLog(@"4-%@",[NSThread currentThread]);

    });

    NSLog(@"5-%@",[NSThread currentThread]); 

```    print 152

执行到         dispatch_sync(queue,^{ 就结束了。

上一篇 下一篇

猜你喜欢

热点阅读