GCD,NSOperationQueue,还是手动创建一个线程? [英] GCD, NSOperationQueue, or create a thread manually?

查看:171
本文介绍了GCD,NSOperationQueue,还是手动创建一个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用线程时,您有任何偏好吗?一般来说,要使用以下任何一种技术:

When you use threads, do you have any preferences? In general rule, to use any of these techniques :


  • 手动创建新线程并使用运行循环

  • 使用NSOperationQueue

  • 或使用Grand Central Dispatch和带有dispatch_queue的C版本?

NSOperationQueue是否简化了所有内容,因此最好在我们需要创建异步函数时使用?

Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function?

推荐答案

我'懒惰,所以我的理念是选择最简单的解决方案来完成我需要的一切。 (我喜欢认为这是Larry Wall所支持的懒惰,但有时我想知道。)

I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy" espoused by Larry Wall but sometimes I wonder.)

所以我的偏好顺序是:


  1. 异步方法调用

  2. NSOperationQueue

  3. Grand Central Dispatch

  4. 线程

  1. Asynchronous method calls
  2. NSOperationQueue
  3. Grand Central Dispatch
  4. Thread

复杂性和灵活性有所增加每走一步。如果你需要额外的灵活性,那么复杂性可能是值得的。

There an increase in complexity and flexibility with each step down. If you need the extra flexibility then the complexity is probably worth it.

这篇关于GCD,NSOperationQueue,还是手动创建一个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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