iOS

iOS-dispatch_queue_t

2016-12-21  本文已影响4人  和谐共处

获取系统队列

1.常见用法
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     NSLog(@"全局队列处理数据");
     dispatch_async(dispatch_get_main_queue(), ^{
         NSLog(@"住队列刷新界面");
     });
 });

自定义队列

1.并行队列,异步执行
dispatch_queue_t queue = dispatch_queue_create("hhq_queue", DISPATCH_QUEUE_CONCURRENT);

dispatch_async(queue, ^{
    NSLog(@"task1==");
});

dispatch_async(queue, ^{
    NSLog(@"task2==");
});

dispatch_async(queue, ^{
    NSLog(@"task3==");
});
同步任务
dispatch_sync(queue, ^{
    NSLog(@"task0==");
});
2.串行队列,异步执行
dispatch_queue_t serialQueue = dispatch_queue_create("hhq_serial_queue", DISPATCH_QUEUE_SERIAL);

dispatch_async(serialQueue, ^{
    NSLog(@"task4==");
});

dispatch_async(serialQueue, ^{
    NSLog(@"task5==");
});

dispatch_async(serialQueue, ^{
    NSLog(@"task6==");
});
上一篇 下一篇

猜你喜欢

热点阅读