Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
i create thread in my C++ Windows application by _beginthread. but all threads are running on a single core, the core apparently the main thread is running. how can i make _beginthread eliminate this barrier and asks OS to dispatch threads over all processors?

What I have tried:

don't know how to. don't have enough experience with threads.
Posted
Updated 15-Dec-16 4:53am
Comments
Philippe Mori 13-Dec-16 16:23pm    
We don't know how to answer you... Not enough code or information for us to know what you are doing wrong.

You can't - the OS is in charge of what threads are running, and where they run: and it can move them between cores as it feels suitable, start and stop them if there is a higher priority thread wanting runtime, and so on.
If all your threads are running on the same core, then either the rest of your system is unbelievably busy, there is something very wrong with your threading code, or they just aren't running long enough for you to notice in practice.
 
Share this answer
 
Comments
ilostmyid2 13-Dec-16 12:31pm    
i think i couldn't describe my problem well. the vmware virtual machine is located on a dual-cpu xeon each have 8 cores. no cpu usage is high. the machine is assigned 10 cpu's, 5 cores from each cpu. when i run 10 threads at a time, i see only the first cpu is involved with my process and threads, while all cores of the other cpu are idle.
Dave Kreskowiak 15-Dec-16 12:05pm    
The problem is VMWare. The threads in a guest O/S do not appear as threads in the host O/S. You can have an enitre guest O/S show up as only a single thread in the host O/S.

No, you do not have any control over this.

And the VMWare component is a very important piece of information that should have been included in your original question.
The load balance is task of the operating system, but you must compile your code as multi-threaded. And all linked libraries must also support this feature.

Read the Microsoft documentation for some details.

Switching threads on different kernels is "costly", so it isnt a good idea to enforce it. Better ways of optimization is a sound architecture and clean program flow ie resource accesses. ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900