The dispatch_main
function is used to make the main thread start processing blocks dispatched to the main queue. So, dispatch_main
is a kind of run loop, which doesn't return and, after processing the already-queued blocks, waits for other blocks to be submitted to the main queue.
So, what happens if dispatch_main
gets called from outside of the main thread? If the main thread is processing another function, is it interrupted in order to allow the main thread to process the queued blocks? Is it allowed to call dispatch_main
from outside of the main thread?
dispatch_main()
asserts when called from outside of the main thread and aborts your process, it must only be called from the main thread.
dispatch_main()
is really nothing other than pthread_exit()
in disguise (see implementation): it turns the main queue into an ordinary serial dispatch queue and then terminates the main thread.
The main queue will be serviced by an on-demand workqueue thread from that point on, just like any other dispatch queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With