calling performSelectorInBackground: from background thread

瘦欲@ 提交于 2019-12-05 20:17:40

What you are doing seems fine to me. Cocoa probably uses a single background thread, so it should not lead to excessive thread creation.

If you want more control, you could use NSOperation or GCD. Both are quite simple. Eg, GCD would be like this

#import <dispatch/dispatch.h>

...

dispatch_async( dispatch_get_global_queue(0,0), ^{
    [self _loop];
}];

performSelectorInBackground forks your selector to a background thread. [documentation]

I don't know if I'm right, but you should do everything using GCD or its high level classes (NSOperationQueue). Forking too many background threads might cause a decrease in performance if the system is saturated with too many threads and have not enough computing resources

GCD automatically manages how many threads operate concurrently based upon available system resources.

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