Can you tell me how can I set a thread to run all of the core of my cpu? I make a thread with:
CreateThread(0, 0, Thread, (LPVOID)1, 0, 0);
but it only run at 25% speed of my cpu, because it only takes 1 core to do calculates. How can I set it to use all the 4 for full speed?
Can you tell me how can I set a thread to run all of
Share
A thread will run on a single core at any one time, though it may be switched between cores by the OS. To have your application take advantage of more than one core then you will need more than one thread.
You can use
CreateThreadto start these threads, or a wrapper around it such asboost::thread, or the new C++11std::thread. If you have four threads (including the first one) then your app can run on 4 cores at once.However, adding threads to an application is not something to do lightly. Multithreading is a complex topic, and can be hard to get right. There are many more difficulties that you may encounter and sources of bugs in multithreaded applications than in single-threaded ones. Consequently, there are many articles and books (including mine) on the topic of multithreaded programming.
Take it slow, read extensively about multithreaded programming, and then look at whether this is the best approach for your application, and how to best make use of those cores.