dispatch_queue_t serial =dispatch_queue_create("thedeeppacific",DISPATCH_QUEUE_CONCURRENT);
dispatch_async(serial, ^{
sleep(1);
NSLog(@"4");
});
dispatch_sync(serial, ^{
sleep(2);
NSLog(@"9");
});
dispatch_async(serial, ^{
sleep(1);
NSLog(@"5");
});
dispatch_sync(serial, ^{
sleep(1);
NSLog(@"8");
4,9,8,5
在同步队列里逐个执行,在异步队列里同步执行。
dispatch_queue_t serial =dispatch_queue_create("thedeeppacific",DISPATCH_QUEUE_SERIAL);
dispatch_sync(serial, ^{
sleep(3);
NSLog(@"1");
});
dispatch_async(serial, ^{
sleep(4);
NSLog(@"13");
});
dispatch_async(serial, ^{
sleep(1);
NSLog(@"11");
});
dispatch_sync(serial, ^{
sleep(2);
NSLog(@"2");
});
dispatch_sync(serial, ^{
sleep(1);
NSLog(@"3");
});
dispatch_async(serial, ^{
sleep(3);
NSLog(@"12");
});
1,13,11,2,3,12
在一个进程里,无论同步异步,都是逐个执行
网友评论