[libdispatch-dev] Regarding dispatch_get_main_queue() and the thread it is actual executing on

Marius Zwicker marius at mlba-team.de
Tue Apr 19 11:04:31 PDT 2011

Am 19.04.2011 um 18:27 schrieb Dave Zarzycki:

> On Apr 19, 2011, at 9:09 AM, Dave Zarzycki wrote:
>> On Apr 19, 2011, at 8:07 AM, Marius Zwicker wrote:
>>> I thought the main queue is available as a mean to be sure some blocks execute on the main thread (e.g. when updating the GUI is only possible while being on the main thread).
>> Marius,
>> That is only true if-and-only-if GCD is working in compatibility mode with Cocoa GUI logic, which for legacy reasons is bound to the main thread. If dispatch_main() is called, then GCD turns the main queue into a normal serial queue, with all of the performance advantages thereof.
> P.S. – This is covered in the dispatch_main() man page:
>      Cocoa applications need not call dispatch_main().  Blocks submitted to
>      the main queue will be executed as part of the "common modes" of the
>      application's main NSRunLoop or CFRunLoop.  However, blocks submitted to
>      the main queue in applications using dispatch_main() are not guaranteed
>      to execute on the main thread.

Thanks a lot for the information. I will try to implement similar functionality when using gui frameworks needing a "real" main thread as well. I assume the portions you were talking about can be found when searching for the DISPATCH_COCOA_COMPAT macro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/libdispatch-dev/attachments/20110419/a326e881/attachment-0001.html>

More information about the libdispatch-dev mailing list