In GCD, are all tasks in a serial queue guaranteed to run on a single thread?

In GCD, are all tasks in the queue of the queue (for example, the main queue) guaranteed to run on the same thread?

+6
source share
1 answer

For serial queues, usually not. From the Concurrency Programming Guide :

Serial queues (also known as private send queues) perform one task at a time in the order in which they are added to the queue. the one currently performing the task runs on a separate thread (which may change from task to task) , which is controlled by the send queue.

For the main line in particular, yes:

The primary send queue is a globally available sequential queue that performs tasks in the main application thread. [...] Since it runs on your application thread, the main queue is often used as a key synchronization point for the application.

+6
source

Source: https://habr.com/ru/post/955684/


All Articles