Choose CPU for a thread

BlitzMax Forums/BlitzMax Programming/Choose CPU for a thread

Scaremonger(Posted 2014) [#1]
Hi,

Is it possible to choose which CPU runs a particular thread, so for example on a Quad core processor I could run one CPU with the main thread and the other three with child processes?

Thanks!


Scaremonger(Posted 2014) [#2]
Ok, I've found some 'threads' (lol) that talk about setting CPU Affinity on Windows, but nothing cross-platform...

ONE, TWO and THREE.


col(Posted 2014) [#3]
Hiya,

Although you have 'some' control with threads in the context that you're asking, the OS is left to decide which cpu core gets assigned the thread task. Due to 'multitasking' there can be hundreds, or more, of thread contexts trying to run concurrently.

Its ok to simply create a thread and be mind worthy that it will run side by side with other threads in your app.


Scaremonger(Posted 2014) [#4]
Maybe what I am thinking of is Process Affinity rather than thread affinity.

The calculation that the child will be performing will likely push one CPU to 100%, so I am trying to find a way to keep it separate so my system (Quad core) doesn't crash during execution.


BlitzSupport(Posted 2014) [#5]
That first link you posted covers setting your process's affinity (on Windows anyway). Also, a single CPU running at 100% won't crash your system -- the OS will simply move other processes/threads to one of the other CPUs.