笔记篇

GCD

2021-08-17  本文已影响0人  失忆的程序员

#pragma mark ----- GCD
- (void)ActionGCD
{
    //创建一个异步队列
    dispatch_queue_t q = dispatch_queue_create("cc_queue2", DISPATCH_QUEUE_CONCURRENT);
    //1.用户登录
    dispatch_sync(q, ^{
        NSLog(@"用户登录 %@", [NSThread currentThread]);
    });

    //2.支付
    dispatch_async(q, ^{
        NSLog(@"支付 %@", [NSThread currentThread]);
    });

    //3.下载
    dispatch_async(q, ^{
        NSLog(@"下载  %@", [NSThread currentThread]);
        [self addTtttt];
        // 追加任务 1
//        [NSThread sleepForTimeInterval:2]; // 模拟耗时操作
        NSLog(@"1---%@", [NSThread currentThread]); // 打印当前线程
    });
    
}

- (void)addTtttt
{
    [NSThread sleepForTimeInterval:2]; // 模拟耗时操作
    XPFLog(@" --------------> tttttttt ");
}


===== 打印 =====

 用户登录 <NSThread: 0x6000030602c0>{number = 1, name = main}
 下载  <NSThread: 0x600003027680>{number = 7, name = (null)}
 支付 <NSThread: 0x6000030222c0>{number = 4, name = (null)}
 .m:(548) > method: -[XDemandsListVC addTtttt]--------------> tttttttt 
 1---<NSThread: 0x600003027680>{number = 7, name = (null)}

上一篇 下一篇

猜你喜欢

热点阅读