看看pthread_setschedparam()
帮助你平衡了线程的使用的CPU
的从pthread_setschedparam
man page,您可以更改线程优先级。
pthread_setschedparam(pthread_t thread, int policy,
const struct sched_param *param);
struct sched_param {
int sched_priority; /* Scheduling priority */
};
As can be seen, only one scheduling parameter is supported. For details of
the permitted ranges for scheduling priorities in each scheduling policy, see
sched_setscheduler(2).
此外,
文件传输正在采取太多的CPU周期,它自己的
如果你读这SO post,这似乎表明,改变线程的优先级可能无法帮助。因为文件传输线程消耗更多CPU周期的原因是它需要它。但在你的情况下,如果文件传输速度减慢,那么你确定没问题,因为流式线程无法与之竞争!因此,我建议您更改优先级和剥夺一些周期的文件传输线程即使需要它
你为什么要通过文件进行通信?为什么不使用'pipe()'? – chrisaycock 2012-04-18 13:20:19
由于接收到的数据可能需要在稍后再次流式传输,这意味着新的文件传输。这样,文件只传输一次,因为它已经存在。 – gekod 2012-04-18 13:22:29
我们在这里谈论的数据量是多少?这是你可以存储在内存中的东西吗? – chrisaycock 2012-04-18 13:26:54