What happens if dispatch_main is called from outside the main thread?

The dispatch_main function is used to send processing units for the start of the main thread to the main queue. Thus, dispatch_main is a kind of loop cycle that does not return and, after processing blocks with already set expectations, expects other blocks to be sent to the main queue.

So what happens if dispatch_main is called from outside the main thread? If the main thread processes another function, is it interrupted so that the main thread processes blocks in the queue? Is dispatch_main allowed from outside the main thread?

+4
source share
1 answer

dispatch_main() asserts when calling from outside the main thread and interrupts your process, it needs to be called only from the main thread.

dispatch_main() is actually nothing more than pthread_exit() in disguise (see implementation ): it turns the main queue into a regular sequential dispatch of the queue, and then terminates the main thread.

The main queue will be served by a workload flow on demand from this point, like any other dispatch queue.

+8
source

Source: https://habr.com/ru/post/1480748/


All Articles