标签:
1
|
dispatch_queue_t myQueue = dispatch_queue_create( "com.iphonedevblog.post" , NULL); |
1
|
dispatch_async(myQueue, ^{ [self doSomething]; }); |
1
2
3
|
dispatch_async(dispatch_queue_create ( "com.iphonedevblog.post" , NULL), ^{ [self doSomething]; } ); |
1
|
dispatch_suspend(myQueue); //恢复一个队列 |
1
|
dispatch_resume(myQueue); |
1
2
3
|
/*dispatch_sync(dispatch_get_main_queue(), ^{ [self dismissLoginWindow]; } );*/ 在主线程中使用会造成死锁,慎用! |
1
2
3
4
5
6
|
-(IBAction)analyzeDocument:(NSButton*)sender{ NSDictionary*stats=[myDoc analyze]; [myModel setDict:stats]; [myStatsViewsetNeedsDisplay:YES]; [stats release]; } |
1
2
3
4
5
6
7
8
9
|
-(IBAction)analyzeDocument:(NSButton*)sender{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{ NSDictionary*stats=[myDoc analyze]; dispatch_async(dispatch_get_main_queue(),^{ [myModel setDict:stats]; [myStatsView setNeedsDisplay:YES]; [stats release];}); }); }; |
1
2
3
4
|
for (i=0;i<count;i++){ results[i]=do_work(data,i); } total=summarize(results,count); |
1
2
3
4
|
dispatch_apply(count,dispatch_get_global_queue(0,0),^(size_ti){ results[i]=do_work(data,i); }); total=summarize(results,count); |
1
2
3
4
5
|
dispatch_queue_t exampleQueue; exampleQueue=dispatch_queue_create( "com.example.unique.identifier" ,NULL); //exampleQueue may be used here. dispatch_release(exampleQueue); |
1
2
3
4
5
6
7
8
9
|
dispatch_queue_t exampleQueue=dispatch_queue_create( "com.example.unique.identifier" ,NULL); dispatch_sync(exampleQueue,^{ dispatch_sync(exampleQueue,^{ printf ( "I am now deadlocked...\n" ); }); }); dispatch_release(exampleQueue); |
标签:
原文地址:http://www.cnblogs.com/mafeng/p/5782176.html