Which thread does the block in dispatch_once run in?

萝らか妹 提交于 2019-12-23 13:15:38

问题


Which thread does the block in dispatch_once run in? Can dispatch_once block run in background thread if the code is run from main thread? How do I ensure it runs on the main thread regardless of which thread executes it?


回答1:


It runs in the current/calling thread. If you wanted I suppose you could use dispatch_sync to ensure it runs on a background thread but I'm not sure what that'd get you. In sum, it runs in the current thread. If another thread is already in the dispatch_once block, the calling thread will block until the block finishes executing on the other thread, and then proceed.



来源:https://stackoverflow.com/questions/25897108/which-thread-does-the-block-in-dispatch-once-run-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!