Dispatch_async & amp; dispatch_sync

Source: Internet
Author: User

Clear that!

 

Dispatch_async sends a block to a specified thread for execution. The current thread does not wait and will continue to execute.

Dispatch_sync also sends the block to the specified thread for execution, but the current thread will be blocked and the block will continue to be executed after the execution of the specified thread is complete.

 

So why is dispatch_sync easy to analyze when it is not used at that time, and it is easy to cause a deadlock to the current thread ~

 

After dispatch_sync and dispatch_async Add the block to the specified thread, the specified thread is executed serially, both FIFO. SoDispatch_sync(Queue, ^ {}); this code still makes sense ~ It will block the current thread and wait until all the tasks in the queue are completed and then run down.

 

However, it is not necessary to useDispatch_syncWhen I read the online saying "the database needs concurrent I/ODispatch_sync", I still don't know what the scenario is ~ We look forward to making some calls...

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.