IOS GCD Programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.