gpt4 book ai didi

objective-c - Objective-C block 是否总是在单独的线程中执行?

转载 作者:太空狗 更新时间:2023-10-30 03:30:34 25 4
gpt4 key购买 nike

Objective-C block 是否总是在单独的线程中执行?

具体来说,我询问的是 NSURLConnection 类的 sendAsynchronousRequest:queue:completionHandler 方法。这是场景:

Main thread (1st thread) calls the sendAsynchronousRequest method the sendAsynchronousRequest is executed on a 2nd thread, managed by the NSOperationQueue when method is completed and calls commpletionHandler, which thread is it executed on? 2nd thread? yet another 3rd thread? or the 1st thread?

谢谢!

最佳答案

它在您指定为 queue 参数的任何操作队列上执行它:

Loads the data for a URL request and executes a handler block on an operation queue when the request completes or fails.

queue 参数记录为:

The operation queue to which the handler block is dispatched when the request completes or failed.

所以这实际上取决于 NSOperationQueue 到底使用了多少线程。我期待池行为 - 所以虽然可以有多个线程,但我不希望每个处理程序有不同的线程,这是必然的。

关于objective-c - Objective-C block 是否总是在单独的线程中执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12685239/

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