Posted at

Grand Central Dispatch

More than 5 years have passed since last update.

覚え書きです。

// Serial Dispatch Queue の作成

dispatch_queue_t serialDispatchQueue = dispatch_queue_create("jp.sample.serialDispatch", NULL);
dispatch_async(serialDispatchQueue, ^{
// do work
});
dispatch_release(serialDispatchQueue);

// Concurrent Dispatch Queue の作成

dispatch_queue_t concurrentDispatchQueue = dispatch_queue_create("jp.sample.concurrentDispatch", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(concurrentDispatchQueue, ^{
// do work
});
dispatch_release(concurrentDispatchQueue);

// Main Dispatch Queue

dispatch_queue_t mainDispatchQueue = dispatch_get_main_queue();

// Global Dispatch Queue
// priority
// DISPATCH_QUEUE_PRIORITY_HIGH
// DISPATCH_QUEUE_PRIORITY_DEFAULT
// DISPATCH_QUEUE_PRIORITY_LOW
// DISPATCH_QUEUE_PRIORITY_BACKGROUND
dispatch_queue_t globalDispatchQueue_high = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);

// dispatch_once

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// 初期化など、アプリケーション中に1回のみ実行される処理
});