Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run multithreaded application on a single core of multicore computer? [duplicate]

I have an application that I need to run multithreaded but I want it to use only one core of the computer, as if my computer has single core (I know the behavior of multithreaded application on a computer with single core), although it is not.

This application is going to be deployed on a customer computer (Windows XP & 7) and I don't want my application to use more than one core. Can this be done? Does it depend on the programming language? Or all the thread management is left to the OS?

Thanks in advance.

like image 291
guneykayim Avatar asked Apr 17 '14 11:04

guneykayim


1 Answers

You can set affinity of the whole program to bind to just one cpu.

In unix you can use taskset but for windows I only know how to do it from task manager which might not suit you.

I have a library, Java Thread Affinity which will allow you to set the affinity programatically.

AffinitySupport.setAffinity(1); // only run on cpu 0.

This will also limit any thread started from that point to the same affinity.

You could add a class with a main() which sets the affinity and calls your normal main() allowing you to add this without altering any of your existing code.

like image 168
Peter Lawrey Avatar answered Oct 20 '22 13:10

Peter Lawrey