|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
multi-threading question
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Programmer
|
Hey guys, I'm working on a multi-threaded program. I want the program to take advantage of multiple cores and I am just wondering if I have to tell the machine to use a specific core for each thread or if it will automatically allocate the thread to an open core. Say the user had a dual core cpu and my program launched 2 threads for execution. Would one thread automatically execute on core 1 and the other on core 2? The program is still on the drawing boards right now but it's either going to be written in C++ or Java. I'm not necessarily looking for code, just for an answer to the question.
Thanks ahead of time!
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Miscelaneous
|
Windows will manage the thread affinity for you, or you can use kernel32.dll to force a thread to execute on a specific core. I recommend letting Windows handle it myself. Windows will chose : is it better to execute them both on this core, or on each core. Pending the work load it may be better to execute on only 1 core and let other programs use the remaining core. However that is unusual, in short : yes it will do this for you (most of the time.)
__________________
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Programmer
|
Ok that works, thanks for the info!
|
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Every base is base 10
|
The scheduler will run whatever thread needs CPU time on whatever core is available when it decides to preempt the currently running thread. Every system has dozens of threads running at a time, and the OS will constantly (every few milliseconds or any time a blocking system call is made) switch between them. It isn't as simple as thread 1 runs on core 1, thread 2 runs on core 2, because there are many threads running and context switches are very frequent.
As a programmer you don't need to worry about any of that. You can manually control those things, but situations in which that would gain performance are few and far between
|
|||||||||||||
|
|
|
|
#5 (permalink) | ||||||||||||||
|
Programmer
|
Quote:
|
||||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||||
|
Miscelaneous
|
Quote:
![]() ![]()
__________________
|
||||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Programmer
|
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|