So far, I couldn't find any mention about this feature. AFAIK, by definition, any GCD queue can run in main thread. If a GCDQ with some heavy task selects main thread to execute on, it'll affect something bad to UI. (I am talking about DispatchQueue.async
case)
Typical workaround for this situation is skipping task if current thread is detected as main thread. But this wastes system resources and introduces unnecessary complexity. I believe there must be a declarative way to do this.
Is there any better way? I have various sized tasks that shouldn't run on main thread. I tried to spawn a separated thread, but it didn't worked well, because macOS lacks unnamed semaphore. Though DispatchSemaphore
is implemented using unnamed semaphores, I am not sure whether it's safe to use DispatchSemaphore
with pthread stuffs as it's GCD level object.