Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><sup>I'm talking mostly about Linux; but I guess what I am saying should be applicable to other OSes. However, without access to Windows source code, no one can reliably say how it behaves in its detail</sup></p> <p>I think your "abstraction" of what a computer is doing is inadequate. Basically, a (mono-threaded) process (or just a thread) is running on some "virtual" CPU, whose instruction set is the unpriviledged x86 machine instructions augmented by the ability to enter the kernel thru syscalls (usually, thru a special instruction like <code>SYSENTER</code>). So from an application point of view, <a href="http://en.wikipedia.org/wiki/System_call" rel="nofollow noreferrer">system calls</a> to the <a href="http://en.wikipedia.org/wiki/Linux_kernel" rel="nofollow noreferrer">linux kernel</a> are "atomic". See <a href="https://stackoverflow.com/a/11609768/841108">this</a> and <a href="https://stackoverflow.com/a/12806838/841108">that</a> answers.</p> <p>Indeed, the processor is getting (at <em>arbitrary</em> instants) some interrupts (on Linux, <code>cat /proc/interrupts</code> repeated twice with a one-second delay would show you how often it is getting interrupted, basically many thousand times per second), and these interrupts are handled by the kernel. The kernel is scheduling tasks (e.g. threads or processes) <a href="http://en.wikipedia.org/wiki/Preemption_%28computing%29" rel="nofollow noreferrer">premptively</a> (they can be interrupted and restarted by the kernel at any time).</p> <p>From an application point of view, interrupts don't really exist (but the kernel can send <em>signals</em> to the process).</p> <p>Cores, interrupts and caches are handled by the hardware and/or the kernel, so from the application point of view, they don't really exist -except by "slowing down" the process. <a href="http://en.wikipedia.org/wiki/Cache_coherence" rel="nofollow noreferrer">cache coherency</a> is mostly dealt with in hardware, and with <a href="http://en.wikipedia.org/wiki/Out-of-order_execution" rel="nofollow noreferrer">out-of-order execution</a> makes a given -even tiny- binary program execution time unpredictable. (in other words, you cannot statically predict exactly how many milliseconds some given routine or loop will need; you can only dynamically measure that; read more about <a href="http://en.wikipedia.org/wiki/Worst-case_execution_time" rel="nofollow noreferrer">worst-case execution time</a>).</p> <p>Reading the <a href="http://advancedlinuxprogramming.com/" rel="nofollow noreferrer">Advanced Linux Programming</a> book and the <a href="http://www.tldp.org/HOWTO/Assembly-HOWTO/" rel="nofollow noreferrer">Linux Assembly Howto</a> would help.</p>
 

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