Page 1 of 1

async I/O

Posted: Sun Dec 29, 2002 4:56 pm
by neowert
What is the point of asynchronus I/O in OS's. Im not posotive, but even on SMP systems the bus cannot do more than 1 thing at a time. Am I right? Like I could not write to memory and a hard disk at the same time.

Re:async I/O

Posted: Sun Dec 29, 2002 6:11 pm
by pskyboy
No you could as the memory and Hard drive use different buses. But otherwise your right you couldn't and i can't see it being done on a none SMP system.

Peter

Re:async I/O

Posted: Sun Dec 29, 2002 6:56 pm
by neowert
I may be very wrong about this, but I thought the CPU wrote to just one bus, but that bus branched into several others. I am just guessing, I have never read about such a thing.

Re:async I/O

Posted: Mon Dec 30, 2002 2:43 am
by Tim
Asynchronous I/O is very useful because it allows an application to do what it wants while waiting for the hardware to finish what it is doing. The bus doesn't come into it, since bus I/O is atomic: bus I/O only takes place during IN or OUT instructions.

Synchronous I/O:

Code: Select all

void read()
{
    queue_command_to_device();
    wait_for_irq();
    read_data_from_device();
    return_results();
}
Asynchronous I/O:

Code: Select all

void read()
{
    queue_command_to_device(completion_function);
    return;
}

static void completion_function()
{
    read_data_from_device();
    return_results();
}
Application using async I/O:

Code: Select all

int main()
{
    handle_t event;

    // Pure async I/O
    read(device, event);
    while (!is_event_signalled(event))
        do_something_useful();

    // Async I/O as sync I/O
    read(device, event);
    wait_for_event(event);
}