gpt4 book ai didi

iOS开发关于NSOperationQueue

转载 作者:行者123 更新时间:2023-11-28 23:12:40 24 4
gpt4 key购买 nike

我知道获取操作队列的两种方法如下:

queue1 = [[NSOperationQueue alloc] init];
queue2 = [[NSOperationQueue mainQueue] retain];

但我不知道它们之间有什么区别。

[queue1 addOperation:operation1]; 
[queue2 addOperation:operation2];

operation1 在哪个线程上运行?主线程?或不确定性?

我测试过。

operation1 --> sometimes mainthread sometimes not. 
operation2 --> always mainthread.

最佳答案

According to the documentation NSOperationQueue 的:

create separate threads for non-concurrent operations and launch concurrent operations from the current thread.

这解释了为什么您的一些任务在主线程上运行而其他任务不运行。

mainQueue 绑定(bind)到主线程,所以操作总是在主线程上执行。

关于iOS开发关于NSOperationQueue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com