Search code examples
windowsmultithreadingexecution

How are threads executed on multiple processors on Windows?


I am on Windows (Windows 7, XP and Vista). If I create a multi-threaded program, will the threads be executed on all available cores? Is it automatic? Is it guaranteed?

For example, if I have four threads and four processors, will the threads be executed one on each processor/core?


Solution

  • They might. It depends on what other programs are running that may be utilizing the various cores as well, up to and including the OS.

    In a nutshell, the OS should try to distribute threads pretty evenly, but trying to predict how and when each thread is placed on each core is an exercise in futility.