如何在其他核心上运行每个线程? [英] how to run each thread on other core?

查看:140
本文介绍了如何在其他核心上运行每个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接收数据并计算它的udp服务器。



每个角色有两个线程。



在我的cpu是一个8多核心,我发送数据的变化速度。



但在maximun我使用ony%14%的我的cpu两个核心50 %。如果我发送更多的数据valume我的缓冲区将fulled和不使用更多的cpu。



为什么每个核心只出现50%,而不是更多?



我想把这两个角色分成多核。



我想确保其他核心上的每一个。 p>

我如何显式地选择在其他核心上运行的每个线程?



我的程序worte在c ++ visaul studio 9和运行在windows7和我使用boost ::线程。

解决方案

调度程序将处理你的线程等将运行。这是操作系统特定的,因此,如果你想尝试改变代码是如何运行的,你需要一个操作系统特定的API,让你设置线程亲和力等。



依赖于你的应用程序是什么样,它的一个客户端服务器的外观,所以它不完全CPU约束。你总共有多少线程,你提到每个角色2?线程只能在一个CPU上运行。尝试制作可以真正并行运行的工作单元,这样,他们可以真正独立运行,理想情况下在不同的核心。



操作系统通常会很好地运行你的代码,因为它会有更好的整体图像。


I have a udp server that receive data and computing it.

I have two thread for each role.

In my cpu is a 8 multi-core and I send data in varius speed.

but at maximun I use ony %14 percent of my cpu two core 50%. if I send more data valume my buffer will fulled and don't use more cpu.

why each core arise only 50% and not more?

I think to divide this two role to multi-core.

I want to be sure that each one on other core.

how I can Explicitly to choose each thread run on other core?

my program worte on c++ visaul studio 9 and run on windows7 and I use boost::thread.

解决方案

The scheduler will deal with where your threads etc will run. This is OS specific, therefore if you want to attempt to alter how code is run you would need an OS specific API that lets you set a threads affinity etc.

Also, depends what you application is like, its a client server by the looks of it, so its not totally CPU bound. How many threads do you have in total, you mention 2 per role? A thread can only be run on one CPU. Try make units of work that can truly run in parallel, that way they can be truly run independently, ideally on different cores.

The OS will generally do a good job of running your code since it will have a better overall picture.

这篇关于如何在其他核心上运行每个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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