Ios – queue attributes in dispatch_queue_create

concurrencyios

In Apple's sample code, AVCam-iOS: Using AVFoundation to Capture Images and Movies, I notice this following line:

// Communicate with the session and other session objects on this queue.
self.sessionQueue = dispatch_queue_create( "session queue", DISPATCH_QUEUE_SERIAL );

And I want to know what the second parameter is about and what other options do we have other than DISPATCH_QUEUE_SERIAL?

And what makes it confusing is that in other Apple documentation, it says that the second parameter is reserved and should be set to NULL. It seems either the documentation is out of date, can anyone explain what the second parameter is supposed to be?

The dispatch_queue_create function takes two parameters: the queue name and a set of queue attributes. The queue attributes are reserved for future use and should be NULL. Concurrency Programming Guide

Best Answer

dispatch_queue_t dispatch_queue_create(const char *label, dispatch_queue_attr_t attr);

Queues are created with the dispatch_queue_create() function. Queues, like all dispatch objects, are reference counted and newly created queues have a reference count of one.

The optional label argument is used to describe the purpose of the queue and is useful during debugging and performance analysis. If a label is provided, it is copied. By convention, clients should pass a reverse DNS style label. For example:

my_queue = dispatch_queue_create("com.example.subsystem.taskXYZ", NULL);

The attr argument specifies the type of queue to create and must be either DISPATCH_QUEUE_SERIAL or DISPATCH_QUEUE_CONCURRENT.

From https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dispatch_queue_create.3.html