Can someone explain to me how and why the solution in this article works? http://blog.benjamin-encz.de/post/main-queue-vs-main-thread/ It is a solution to check whether you are running on the main queue. I understand the problem, I just don't understand how using dispatch_queue_set_specific and dispatch_get_specific to retrieve a key-value pair matters in any way.
Uunfortunately, I don't remember where that was, or the exact details of what was said. It might have been on the old developer forums, or one of the developer mailing lists. If was a comment about being careful testing what the "current" queue is, because you might be surprised by the results.
It's something to do with the fact that most dispatch queues are actually references to other dispatch queues. There is a limited set of "base" queues, and if you declare your own queues, they actually target (directly or indirectly) one of the base queues.
If you're interested, I think this 2017 WWDC video discusses the sorts of re-arrangements that go on behind the scenes:
https://developer.apple.com/videos/play/wwdc2017/706/
The optimizations talked about here are new, but IIRC this will give you a "flavor" for the complexity behind GCD.