What thread does the block execute in dispatch_once?

In which thread does the block in manager_once work? Can the dispatch_once block work in the background thread if the code is launched from the main thread? How to ensure that it runs in the main thread no matter which thread executes it?

+4
source share
1 answer

It works in the current / calling thread. If you want, I suppose you could use dispatch_syncto make sure that it works in the background thread, but I'm not sure what you would get. In general, it works in the current thread. If another thread is already in the block dispatch_once, the calling thread will block until the block completes execution in the other thread, and then continue.

+5
source

All Articles