5

Appleのドキュメントにあるように、dispatch_get_global_queue()は並行キューであり、dispatch_syncはシリアルを意味するものです。その後、タスクは非同期または同期で処理されますか?

4

2 に答える 2

33

キューとは何か、非同期と同期の意味との間で混乱しています。

キューは、ブロックを実行できるエンティティです。これらは、シリアルまたはコンカレントにすることができます。シリアルとは、A、B、C、D の順序でブロックを配置した場合、A、B、C、D の順に実行されることを意味します。同時実行とは、これらの同じブロックが異なる順序で実行され、場合によっては実行される可能性があることを意味します。同時に複数のコアを実行することもできます (明らかに、実行するコアが複数あると仮定します)。

次に、非同期と同期について説明します。非同期とは、 を呼び出すとすぐdispatch_asyncに戻り、ブロックがキューに入れられることを意味します。同期とは、呼び出したときに、ブロックの実行が終了した後にのみ返されることを意味します。dispatch_sync

したがって、質問に完全に答えるためにdispatch_sync、グローバルな同時キューにアクセスすると、このブロックはおそらくそのキューの他のブロックと並行して実行されますが、同期的に実行されます。つまり、ブロックが終了するまで戻りません。

于 2012-03-22T13:13:36.123 に答える
0

Apple Doc says

dispatch_get_global_queue

Returns a well-known global concurrent queue of a given priority level.

dispatch_queue_t dispatch_get_global_queue( long priority, unsigned long flags);

Parameters

priority The priority of the queue being retrieved. For a list of possible values, see “dispatch_queue_priority_t”. flags This value is reserved for future use. You should always pass 0. Return Value Returns the requested global queue.

Discussion

The well-known global concurrent queues cannot be modified. Calls to dispatch_suspend, dispatch_resume, dispatch_set_context, and the like have no effect when used with queues returned by this function.

Blocks submitted to these global concurrent queues may be executed concurrently with respect to each other.

Availability Available in iOS 4.0 and later. Declared In dispatch/queue.h

In the Discussion they have said that-> 'blocks submitted MAY be executed concurrently wrt each other.'

So Tasks may be processed Async with each other.

于 2012-03-22T12:53:09.293 に答える