Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Utilizing Dual/Quad core Technology

In C#, when I create a new thread and execute a process on that thread, is there a way to assign it to a particular core? Or does the operating system handle all that automatically? I wrote a multi threaded application and I just want to be sure its optimized for dual/quad core functionality.

Thanks

like image 558
Icemanind Avatar asked Dec 13 '22 02:12

Icemanind


1 Answers

You can force your threads to run on specific cores, but in general you should let the OS take care of it. The operating system handles much of this automatically. If you have four threads running on a quad core system, the OS will schedule them on all four cores unless you take actions to prevent it from happening. The OS will also do things like try to keep an individual thread running on the same core rather than shifting them around for better performance, not schedule two running threads on the same hyperthreaded core if there are idle cores available, and so on.

Also, rather than creating new threads for work you should use the thread pool. The system will scale this to the number of processors available on the system.

Windows Internals is a good book for covering how the Windows scheduler works.

like image 173
Michael Avatar answered Dec 16 '22 17:12

Michael