Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The principles of how an OS schedules threads on a multicore computer aren't so different to how it is done on a single core machine. In effect each core is running a copy of the OS'es scheduler, and those talk to each other and decide how best to allocate threads to cores. If one of those schedulers finds that it has no ready threads to run on its core it will run a ready thread that's blocked in another core.</p> <p>The thing is that those cores are mostly asynchronous and independent of each other, and there really is no guarantee of order of execution. So the order in which strings are output by different threads is not deterministic and can easily be different every time you run the program. </p> <p>All this works because multicore computers of today implememt Symetrical Multi Processing (SMP). All cores can see all memory, so there is no real problem in choosing which core is the best one to run a thread.</p> <p>However, the SMP we get from Xeons and the like is 'fake', that is they're partly NUMA with SMP synthesised by QPI. AMD processors are entirely NUMA with SMP being synthesised over Hypertransport. QPI and HyperTransport are very good, but there is an overhead which an OS shouldn't ignore. In short, it takes longer for a thread on one core to access memory that is electronically connected to a different core. So a good OS will attempt to run threads on cores closest to the memory they're accessing so as to get good performance. In Xeon land this is veeery complicated because the machine's default memory map is interleaved between CPUs (an attempt to make the faked SMP better). </p> <p>So as soon as you start delving into core affinity and binding threads to particular cores (something that OSes allow you to do if you really want to) your program has to fully understand the microelectronic architecture of the hardware it happens to find itself running on. In general that's not wholly realistic and in almost all cases its probably better to just let the OS sort things out for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload