0

I've recently been trying to wrap my brain around asynchronous I/O, that is, epoll() on Linux and kqueue() on FreeBSD; instead of creating multiple threads and using something like select(), you can create only one thread and still respond to many I/O events at once.

I've been trying to understand how this works at a deep level in the machine code, but have hit a brick wall. (Perhaps my Google-Fu is just lacking.) I can't seem to find any CPU instructions related to async I/O at all - so how does it work?

Fredrick Brennan
  • 7,079
  • 2
  • 30
  • 61
  • not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like `mov`s... – Ped7g Nov 22 '18 at 09:55
  • 3
    `epoll`, `kqueue` and `select` all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls. – Ross Ridge Nov 22 '18 at 10:35
  • 1
    There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet. – fuz Nov 22 '18 at 12:51
  • 1
    Fundamentally, asynchronous I/O is done with interrupts. – EOF Nov 22 '18 at 18:52

0 Answers0