Monday, June 6, 2016 [Tweets] [Favorites]

GCD’s Main Queue vs. Main Thread

Benjamin Encz (tweet):

Technically I think this is a MapKit / VektorKit bug, Apple’s UI frameworks typically guarantee to work correctly when being called from the main thread, no part of the documentation mentions that code needs to be executed on the main queue.

[…]

By combining GCD and Cocoa’s NSThread API we are drilling through the abstraction that GCD should provide in the first place. APIs that fully rely on GCD and ignore the presence of the underlying threads can run into problems if you call them on the main thread but not the main queue. This means, especially when calling into other frameworks, we should prefer using dispatch_queue_set_specific and dispatch_get_specific to check if our code is running on the main queue over using NSThread.isMainThread().

It’s hard to get this right because of reentrancy, though.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment