async I/O

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
neowert

async I/O

Post 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.
pskyboy

Re:async I/O

Post 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
neowert

Re:async I/O

Post 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.
Tim

Re:async I/O

Post 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);
}
Post Reply