çlinux下的pthread线程优先级 [英] C linux pthread thread priority

查看:340
本文介绍了çlinux下的pthread线程优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序有一个后台线程填充并交换双缓冲区实现的后台缓冲区。
主线程使用前缓冲区发送出去的数据。问题是,主线程获取更多的处理时间平均为当我运行该程序。我想相反的行为,因为填充后缓冲器是一个更耗时的过程,则处理和数据发送到客户端。

My program has one background thread that fills and swaps the back buffer of a double buffer implementation. The main thread uses the front buffer to send out data. The problem is the main thread gets more processing time on average when I run the program. I want the opposite behavior since filling the back buffer is a more time consuming process then processing and sending out data to the client.

我怎样才能做到这一点用C POSIX的pthreads在Linux上?

How can I achieve this with C POSIX pthreads on Linux?

推荐答案

在我的经验,如果在没有优先的你的主线程也越来越CPU那么这意味着两件事情之一:

In my experience, if, in the absence of prioritisation your main thread is getting more CPU then this means one of two things:


  1. 它确实需要额外的时间,出乎你的意料,或

  1. it actually needs the extra time, contrary to your expectation, or

后台线程被饿死,或许是由于锁争

the background thread is being starved, perhaps due to lock contention

更改优先级不会解决这类原因。

Changing the priorities will not fix either of those.

这篇关于çlinux下的pthread线程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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