GCD

作者: 失忆的程序员 | 来源:发表于2021-08-17 15:55 被阅读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)}
    
    

    相关文章

      网友评论

        本文标题:GCD

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