c++ - 带有 pthreads 的后台线程

标签 c++ ios pthreads

我正在使用pthreads创建一个后台线程来加载并在后台执行一些任务,但它有点滞后于应用程序,因为它的工作有时很紧张。

有什么方法可以设置较低的优先级或不同的调度(或两者的组合),以便主线程有更多的 CPU 时间来运行?

最佳答案

这并没有逐字回答你的问题,但是 在 Concurrency Programming Guide Apple 建议放弃线程并使用“调度队列”或 例如,OS X 和 iOS 上异步操作的“操作队列”

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // ... background task
});

DISPATCH_QUEUE_PRIORITY_LOW记录为

Items dispatched to the queue run at low priority; the queue is scheduled for execution after all default priority and high priority queues have been scheduled.

关于c++ - 带有 pthreads 的后台线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16654544/

相关文章:

C++ 常量截断

c++ - 元组在哪里存储其数据?

ios - 以编程方式在 UIAlertController 中获取不断变化的文本字段

ios - 当我调用 ".stop()"方法时,Swift/Xcode6 AVAudioPlayer 崩溃

objective-c - xcode 'NSInvalidArgumentException',原因: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

c++ - 如何将 Python 中的脚本转换为 C++?

c - 通过 pthread_join() 加入两个 pthread 无法按预期工作

c++ - 为什么 __thread 在使用 printf 语句时给出链接器错误?

c++ - pthread_getschedparam 没有匹配的函数调用

c++ - 从模板成员类型派生模板化类的成员变量类型