在后台线程调用函数ios - 嵌套函数调用会发生什么 [英] calling a function on a background thread ios-what happens to the nested function calls

查看:165
本文介绍了在后台线程调用函数ios - 嵌套函数调用会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主代码中(为了显示UIActivityIndi​​catorView)我在背景线程上调用函数foo()。 foo()调用的函数又会发生什么变化?这些函数是否会在同一个后台线程中调用和执行?

解决方案

是的,它也会在同一个后台线程。



实际上很简单:您调用的所有内容都将与调用方在同一个线程中运行,除非您明确地使用方法创建一个新线程并在那里运行一个方法或者导致一个方法在另一个线程中运行(例如 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆