Using GCD to handle multi-threading, under a multi-core CPU, will improve execution efficiency, and here is a section of the GCD code used in the project.
-(void) gcddownload { static dispatch_once_t once; static dispatch_queue_t queue; Create download Queue dispatch_once (&once, ^{ queue =dispatch_queue_create (" Com.xxx.download.background ", dispatch_queue_concurrent); }); __block type __block BOOL downloadflag = NO; Dispatch_async (queue, ^{ // Downloadflag = [Download sendrequest:request]; NSLog (@ "Long-time tasks, such as network Downloads"); }); Dispatch_barrier_async (queue,^{ if (downloadflag) { NSLog (@ "Download completed successfully"); } Dispatch_async (Dispatch_get_main_queue (), ^{ NSLog (@ "finished downloading, back to the main thread, such as Refresh UI");});
Multiple concurrent blocks can be placed in the queue.
IOS GCD Programming