我正在使用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/