我们可以在 iPhone 应用程序中使用 pthread 代替 NSThread
嗯,我有一个同时使用 Objective C 和 Objective C 的应用程序。 c++,但出于可移植性的原因,我尝试尽可能多地使用c++......现在我遇到了一些需要线程的问题,我正在考虑使用 pthread
而不是 NSThread...使用
pthread
可以吗?苹果会因为我使用它而在应用商店拒绝我的应用程序来惩罚我吗?
Well I have an application that uses both Objective C & c++ but for portability reasons I have tried to use c++ as much as possible.... Now I am confronted with some problem that requires threads I was thinking of using pthread
instead of NSThread
... is it Okay to use pthread
? Will Apple punish me for using it by rejecting my app on the appstore...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSThread
是围绕pthread
构建的,无论如何,我看不出有任何理由使用
pthread
会导致 Apple 方面的拒绝NSThread
is built aroundpthread
anywayI can't see any reason why using
pthread
would lead to rejection from Apple's partNSThread 主要是 pthread 语义的包装器。
优点:
- NSThread退出时的NSThreadWillExitNotification通知
- NSMutableDictionary 线程本地存储
限制:
- 你只能创建分离的 NSThread
请注意,Cocoa 需要知道你想要进行多线程。首先分离一个虚拟的 NSThread 非常重要,这样应用程序就可以 考虑多线程。
NSThread is mostly a wrapper around pthread semantics.
Advantages:
- NSThreadWillExitNotification notification when NSThread exits
- A NSMutableDictionary thread-local storage
Limitations:
- you can only create detached NSThread
Be aware that Cocoa needs to know that you want to do multi-threading. It is important to first detach a dummy NSThread so the application can be considered multi-threaded.
我的应用程序使用 pthread API,将调度策略从 SCHED_OTHER 更改为 SCHED_FIFO,并更改线程的优先级。
效果很好。
但是,我避免在线程中使用Cocoa touch框架API,因为我不知道pthread而不是NSThread的副作用。
My app uses pthread API, changes the scheduling policy from SCHED_OTHER to SCHED_FIFO, and changes thread's priority.
It works well.
However, I avoid using Cocoa touch framework APIs in the thread because I don't know the side effect of pthread instead of NSThread.