标签:
dispatch_queue_t :
创建方法:
dispatch_queue_t queue = dispatch_queue_create("myblockqueue",DISPATCH_QUEUE_CONCURRENT);
DISPATCH_QUEUE_CONCURRENT //并发 DISPATCH_QUEUE_SERIAL //串行
串行的队列也就是添加进去的一个一个block是按顺序执行,比如:
dispatch_queue_t queue = dispatch_queue_create("myblockqueue", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
sleep(3);
NSLog(@"1");
});
dispatch_async(queue, ^{
NSLog(@"2");
});
结果是:
1
2
而并发的队列是:
dispatch_queue_t queue = dispatch_queue_create("myblockqueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
sleep(3);
NSLog(@"1");
});
dispatch_async(queue, ^{
NSLog(@"2");
});
结果是
2
1
还有三种队列是系统定义的队列,根据优先级别不同有3种:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //获取系统的queue
#define DISPATCH_QUEUE_PRIORITY_HIGH 2 #define DISPATCH_QUEUE_PRIORITY_DEFAULT 0 #define DISPATCH_QUEUE_PRIORITY_LOW (-2)
当然,也可以获取主线程队列
标签:
原文地址:http://www.cnblogs.com/wangyutao/p/4381621.html