在后台线程调用函数ios - 嵌套函数调用会发生什么 [英] calling a function on a background thread ios-what happens to the nested function calls
问题描述
是的,它也会在同一个后台线程。
实际上很简单:您调用的所有内容都将与调用方在同一个线程中运行,除非您明确地使用方法创建一个新线程并在那里运行一个方法或者导致一个方法在另一个线程中运行(例如 performSelectorOnMainThread:withObject:waitUntilDone:
)。但是从这些方法上来看,它们又是一样的:它们将和它们的调用者在同一个线程中运行。
In my main code(in order to show UIActivityIndicatorView) I'm calling a function, foo() on a background thread. What happens to the functions called by foo() in turn? Will those functions also be called and executed in the same background thread?
Yes, it will also be called in that same background thread.
It's actually pretty easy: everything you call will be run in the same thread as the caller, unless you explicitly use methods to create a new thread and run a method there or cause a method to be run in another thread (e.g. performSelectorOnMainThread:withObject:waitUntilDone:
). But from those methods on it's the same again: they will be run in the very same thread as their callers.
这篇关于在后台线程调用函数ios - 嵌套函数调用会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!