A Brief Introduction to concurrency

Source: Internet
Author: User

Introduction:

Concurrency occurs when two or more tasks are executed simultaneously. even if there is only one CPU, the modern operating system can execute multiple tasks at the same time. to achieve this, you need to allocate a certain time slice to each task from the CPU. for example, if you want to execute 10 characters of the same limited level within one second, the operating system will use 10 to allocate an average of 1000 milliseconds, and each task will have a CPU time of 100 milliseconds.

As technology advances, there are more than one core of the CPU, which means that the CPU has the ability to execute multiple tasks at the same time.

Grand Central Dispatch (dispatch [dispatch, dispatch]), referred to as GCD, is an underlying c api that works with block objects. the real purpose of GCD is to allocate tasks to multiple cores without worrying about which kernel to execute.

The core of GCD is the dispatch queue. you do not directly have a working relationship with the thread. You only work in the dispatch queue, assign the task to this queue, and require the queue to call your task. GCD provides several options for running a task: Synchronous asynchronous execution of delayed execution.

 

To start using GCD in the app, you do not need to import any special libraries into your project. GCD. All methods and data types start with the dispatch _ keyword. For example, dispatch_async allows you to assign tasks in a queue for asynchronous execution, while dispatch_after allows you to run a block after a given delay.

 

A Brief Introduction to concurrency

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.