[size=13.3333330154419px]dispatch_barrier_async是在前面的任务执行结束后它才执行,而且它后面的任务等它执行完成之后才会执行 [size=13.3333330154419px]例子代码如下:
- dispatch_queue_t queue = dispatch_queue_create("gcdtest.rongfzh.yc", DISPATCH_QUEUE_CONCURRENT);
- dispatch_async(queue, ^{
- [NSThread sleepForTimeInterval:2];
- NSLog(@"dispatch_async1");
- });
- dispatch_async(queue, ^{
- [NSThread sleepForTimeInterval:4];
- NSLog(@"dispatch_async2");
- });
- dispatch_barrier_async(queue, ^{
- NSLog(@"dispatch_barrier_async");
- [NSThread sleepForTimeInterval:4];
-
- });
- dispatch_async(queue, ^{
- [NSThread sleepForTimeInterval:1];
- NSLog(@"dispatch_async3");
- });
[size=13.3333330154419px]打印结果:
[size=13.3333330154419px]2012-09-25 16:20:33.967 gcdTest[45547:11203] dispatch_async1 [size=13.3333330154419px]2012-09-25 16:20:35.967 gcdTest[45547:11303] dispatch_async2 [size=13.3333330154419px]2012-09-25 16:20:35.967 gcdTest[45547:11303] dispatch_barrier_async [size=13.3333330154419px]2012-09-25 16:20:40.970 gcdTest[45547:11303] dispatch_async3
|