iOS Multithreading-GCD basic usage

Source: Internet
Author: User

There are three types of multithreading in iOS, Nstread, NSOPERATION,GCD

This article is about the basic use of GCD.

Usually more use and see is:

0), ^{        // Async Action code block          ^{            //  Back to the main thread operation code block         })    ;

More for updating UI actions

For example, it takes a long time to get the data from the database, and does not want the main thread of the card, put the database data operation in the asynchronous operation code fast, and so on to get the end, callback the main thread, update the UI, in the main thread operation code block to operate

Let's take a look at each of the methods in this code block:

Dispatch_async (< #dispatch_queue_t queue#>, <#^ (void) block#>) represents an asynchronous operation, which corresponds to a dispatch_sync (< #dispatch_queue_t Queue#>, <#^ (void) block#>), synchronous operation, the code in the block executes in order to perform the first parameter in the following action method the dispatch_queue_t queue represents queues, nothing more than two kinds: serial and parallel, in addition to self-built serial or parallel queue to obtain the system serial queue, That is, the main thread serial queue: Dispatch_get_main_queue () Gets the system parallel queue: Dispatch_get_global_queue (Dispatch_queue_priority_default,0The first parameter, which is the queue priority, has four types:#defineDispatch_queue_priority_high 2#defineDispatch_queue_priority_default 0#defineDispatch_queue_priority_low (-2)#defineDispatch_queue_priority_background Int16_minThe self-built queue is processed according to the priority level: Dispatch_queue_create ("com.example.serial", NULL); The first argument, the document specification says: Astringlabel to attach to the queue. This string needs to be unique, usually in the form of the second argument to null or dispatch_queue_serial to represent a serial pass Dispatch_queue_ Concurrent said and the business execution end, must have Dispatch_release (), the queue release

Recently saw an article about GCD, more in-depth, and some do not understand, above I described the content is GCD more basic usage, general procedures are used to these

http://justsee.iteye.com/blog/1883409

Thanks to the author for such in-depth analysis, benefited

iOS Multithreading-GCD basic usage

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.