Hacker News new | ask | show | jobs
by LowerThanZero 2230 days ago
Not necessarily. See, at hardware level the CPU can use what is called an "interrupt". In its simplest form it's a CPU pin that receives electrical signals from the outside world. The CPU can then well... interrupt from what it was doing and see what the problem was. That part of code which is run when the interrupt occurs it's called "interrupt handler". Say you wanna read a sector from a disk drive and your disk controller is hooked to the interrupt signal of the CPU... you tell the drive controller "gimme sector X" and then you (as a OS kernel) mind your own business doing other things. Once the platter spins in the right position and the read head is positioned etc etc that is milliseconds later the controller gets what you asked for and it issues an "interrupt" for the CPU. The kernel interrupt handler will go and fetch the desired block. Or even better, a DMA controller can do the job and take the data from the disk controller and move it somewhere in memory then only bother the CPU to say "The required block has arrived your highness" ;-)

Network controllers can issue interrupts so you know a packet has arrived... keyboard controllers too and so on. Hopefully you get the idea. :)

1 comments

Wow thanks so much. This really click in for me.

> In its simplest form it's a CPU pin that receives electrical signals from the outside world.

That is truly async :-).