Profitability between different processes

I have two C ++ codes, one of which is called a and one is called b. I work on 64-bit Linux using the Threading Boost library.

The code creates 5 threads that remain in an infinite loop, performing some operation. B code creates 5 threads that remain in an infinite loop that calls yield ().

I'm on a quad-core computer ... When you only call the code, it gets almost 400% of the CPU usage. When you call only b-code, it gets almost 400% of CPU usage. I already expected this.

But when I worked together, I expected that code b uses almost nothing for the CPU and uses 400%. But in fact, both use an equal processor fragment, almost 200%.

My question is: Doesn't () work between different processes? Is there any way to make it work as I expected?

+5
source share
2 answers

Linux uses dynamic thread priority. The static priority you set with nice is just a limitation of the dynamic priority.

When a thread uses its entire time interval, the kernel will reduce its priority, and when the thread will not use its entire time-lapse (by doing IO, calling wait / yield, etc.), the kernel will increase its priority.

So, I assume that process b threads has a higher priority, so they are executed more often.

+2
source

, 4 4 , A. 6 - 1 A 5 B. Thread . . , B? 5/6. , , sched_yield() . , B? 5/6 !

B , ​​ .

sched_yield - runnable (, ). B , A - , , B , A .

+3

All Articles