1- (void) gcdmethed{2 //Background Execution3Dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_high,0), ^{4 5 //actions performed in the background6NSLog (@"Background Operation");7 });8 9 //Main thread ExecutionTenDispatch_async (Dispatch_get_main_queue (), ^{ One A //operations performed by the main thread -NSLog (@"Main thread Operation"); - }); the - - //Disposable Execution - for(intI=0; i<2; i++) { + Staticdispatch_once_t Oncetoken; -Dispatch_once (&oncetoken, ^{ + //code executes once ANSLog (@"code executes once"); at }); - } - - //2 seconds delay execution - DoubleDelayinseconds =2.0; -dispatch_time_t poptime = Dispatch_time (Dispatch_time_now, (int64_t) (Delayinseconds *nsec_per_sec)); inDispatch_after (Poptime, Dispatch_get_main_queue (), ^ (void){ -NSLog (@"delayed 2 seconds of execution"); to }); + - //Custom dispatch_queue_t thedispatch_queue_t Urls_queue = Dispatch_queue_create ("blog.devtang.com", NULL); *dispatch_queue_t urls_queue2 = Dispatch_queue_create ("TEST", dispatch_queue_concurrent);//Parallel Queue dispatch_queue_serial Walkthrough Queue $Dispatch_async (Urls_queue, ^{Panax Notoginseng - }); the //dispatch_release (Urls_queue); ARC does not need + A the //Merge Summary Results + -dispatch_group_t Group =dispatch_group_create (); $Dispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{ $ //thread one in parallel execution - }); -Dispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{ the //threads executed in parallel two - });WuyiDispatch_group_notify (Group, Dispatch_get_global_queue (0,0), ^{ the //Summary Results - }); Wu -Dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^{ About $Dispatch_async (Dispatch_get_main_queue (), ^{ - - }); - }); A +}
iOS gcd some ways to use