Grand Central Dispatch - Design

Design

GCD works by allowing specific tasks in a program that can be run in parallel to be queued up for execution and, depending on availability of processing resources, scheduling them to execute on any of the available processor cores (referred to as "routing" by Apple).

A task can be expressed either as a function or as a "block." Blocks are an extension to the syntax of C, C++, and Objective-C programming languages that encapsulate code and data into a single object in a way similar to a closure. GCD can still be used in environments where blocks are not available.

Grand Central Dispatch still uses threads at the low level but abstracts them away from the programmer, who will not need to be concerned with as many details. Tasks in GCD are lightweight to create and queue; Apple states that 15 instructions are required to queue up a work unit in GCD, while creating a traditional thread could easily require several hundred instructions.

A task in Grand Central Dispatch can be used either to create a work item that is placed in a queue or assign it to an event source. If a task is assigned to an event source then a work unit is made from the block or function when the event triggers, and the work unit is placed in an appropriate queue. This is described by Apple as more efficient than creating a thread whose sole purpose is to wait on a single event triggering.

Read more about this topic:  Grand Central Dispatch

Famous quotes containing the word design:

    Westerners inherit
    A design for living
    Deeper into matter—
    Not without due patter
    Of a great misgiving.
    Robert Frost (1874–1963)

    Joe ... you remember I said you wouldn’t be cheated?... Nobody is really. Eventually all things work out. There’s a design in everything.
    Sidney Buchman (1902–1975)

    I begin with a design for a hearse.
    For Christ’s sake not black—
    nor white either—and not polished!
    Let it be weathered—like a farm wagon—
    William Carlos Williams (1883–1963)