Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Comparing the current queue against the main queue is not a valid way to check whether you are running on the main thread.</p> <p>Use <code>[NSThread isMainThread]</code> or <code>pthread_main_np()</code> to explicitly check whether you are on the main thread if that is what you want to know.</p> <p>You can be on the main thread without the current queue being the main queue, and you can be on the main queue without the current thread being the main thread (the latter only if <code>dispatch_main()</code> has been called, but still).</p> <p>In recent releases this is documented explicitly in the CAVEATS section of the dispatch_get_main_queue(3) manpage:</p> <blockquote> <p>The result of dispatch_get_main_queue() may or may not equal the result of dispatch_get_current_queue() when called on the main thread. Comparing the two is not a valid way to test whether code is executing on the main thread. Foundation/AppKit programs should use [NSThread isMainThread]. POSIX programs may use pthread_main_np(3).</p> </blockquote> <p>In general you should avoid using queue pointer comparison to influence program logic. Dispatch queues exist in a dependency tree (the target queue hierarchy) and comparing individual leaves in that tree without taking their interdependency into account does not provide sufficient information to make safe decisions.</p> <p>If you really need program logic based on queue interdependency, use the <code>dispatch_get_specific(3)</code>/<code>dispatch_queue_set_specific(3)</code> APIs which are target-queue aware and much more explicit.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload