GCD understanding 1 (synchronous-asynchronous, serial-parallel), gcd asynchronous

Source: Internet
Author: User

GCD understanding 1 (synchronous-asynchronous, serial-parallel), gcd asynchronous

1. Parallel-asynchronous (ST1 and ST2 seize resources)

1-1) obtain the parallel (global) queue. The default priority is DISPATCH_QUEUE_PRIORITY_DEFAULT.

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT , 0);

1-2) create an asynchronous event.

dispatch_async(queue, ^{//do something 1   });dispatch_async(queue, ^{//do something 2   });

 

2. Serial-synchronization (sequential execution)

2-1) create a serial queue, and DISPATCH_QUEUE_SERIAL is a serial

dispatch_queue_t queue =  dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);

2-2) create a synchronization event.

dispatch_sync(queue, ^{//do something 1    });dispatch_sync(queue, ^{//do something 2   });

 

3. Parallel-synchronization (sequential execution)

3-1) obtain the parallel (global) queue. The default priority is DISPATCH_QUEUE_PRIORITY_DEFAULT.

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT , 0);

3-2) create a synchronization event.

dispatch_sync(queue, ^{//do something 1    });dispatch_sync(queue, ^{//do something 2   });

 

4. Serial-asynchronous (strange to understand, test results, and sequential execution)

4-1) create a serial queue, and DISPATCH_QUEUE_SERIAL is a serial

dispatch_queue_t queue =  dispatch_queue_create("test", DISPATCH_QUEUE_SERIAL);

4-2) create an asynchronous event.

dispatch_async(queue, ^{//do something 1    });dispatch_async(queue, ^{//do something 2   });

 

Generally, 1-3 is enough, right ?!

Related Article

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.