Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

线程、同步异步、队列

 

 1  dispatch_queue_t _serialQueue = dispatch_queue_create("gao mao a", DISPATCH_QUEUE_SERIAL);
 2     //(两个队列,都是同步的时候,就没什么卵用了,一个队列就够了)
 3     dispatch_queue_t _gaomaoa  = dispatch_queue_create("gao maoss a", DISPATCH_QUEUE_SERIAL);
 4     
 5     NSLog(@"wo ca lei ge da ye =======  1  \n");
 6     //同步
 7     dispatch_async(_gaomaoa, ^{
 8         NSLog(@"wo ca lei ge da ye =======  2  \n");
 9         NSLog(@"wo ca lei ge da ye =======  2  \n");
10         NSLog(@"wo ca lei ge da ye =======  2  \n");
11         NSLog(@"wo ca lei ge da ye =======  2  \n");
12         NSLog(@"wo ca lei ge da ye =======  2  \n");
13     });
14     //异步
15     dispatch_sync(_serialQueue, ^{
16         NSLog(@"wo ca lei ge da ye =======  3  \n");
17         NSLog(@"wo ca lei ge da ye =======  3  \n");
18         NSLog(@"wo ca lei ge da ye =======  3  \n");
19         NSLog(@"wo ca lei ge da ye =======  3  \n");
20         NSLog(@"wo ca lei ge da ye =======  3  \n");
21     });
22     
23     dispatch_sync(_serialQueue, ^{
24         NSLog(@"wo ca lei ge da ye =======  4  \n");
25         NSLog(@"wo ca lei ge da ye =======  4  \n");
26         NSLog(@"wo ca lei ge da ye =======  4  \n");
27         NSLog(@"wo ca lei ge da ye =======  4  \n");
28         NSLog(@"wo ca lei ge da ye =======  4  \n");
29     });
30     
31     NSLog(@"wo ca lei ge da ye =======  5  \n");
32     
33     NSLog(@"wo ca lei ge da ye =======  6  \n");

 

打印结果

2016-03-29 16:33:07.522 neeq_second[903:130796] wo ca lei ge da ye =======  1  

2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

2016-03-29 16:33:07.523 neeq_second[903:130796] wo ca lei ge da ye =======  3  

2016-03-29 16:33:07.523 neeq_second[903:130815] wo ca lei ge da ye =======  2  

2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  3  

2016-03-29 16:33:07.524 neeq_second[903:130815] wo ca lei ge da ye =======  2  

2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

2016-03-29 16:33:07.524 neeq_second[903:130796] wo ca lei ge da ye =======  4  

2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  4  

2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  5  

2016-03-29 16:33:07.525 neeq_second[903:130796] wo ca lei ge da ye =======  6  

 

posted on 2016-03-29 16:38  Sinner_Yun  阅读(362)  评论(0编辑  收藏  举报

导航