Sobes.tech
Junior — Middle

Which GCD queue is responsible for executing the passed code block?

sobes.tech AI

Answer from AI

In GCD (Grand Central Dispatch), the execution of a passed code block occurs in a dispatch queue. The code block itself is placed in the queue, and then the system selects a thread for its execution. Thus, the thread is not chosen directly by the developer but is managed by the system. It is important to understand that GCD uses a thread pool, and the specific thread on which the block executes can change.

Example of creating and executing a block in the global queue:

DispatchQueue.global().async {
    // Code that will execute asynchronously on one of the pool's threads
    print("Executing block")
}