|
Boost : |
From: Alf P. Steinbach (alf_p_steinbach_at_[hidden])
Date: 2005-03-29 08:59:23
Boris wrote:
> Robert Ramey wrote:
>> Windows has the concept of "Overlapped I/O" which permits dispatch of
>> an i/o request that invokes a call back when done.
>>
>> Posix has aio which functions (I believe) in a similar way.
>>
>> So one has the concept of asyncronous i/o without any explicit
>> reference to threads at least at the application level.
>
> I am not sure if I understand correctly. Just as Don I think we can't
> get around threads when we have callbacks. I don't know about Windows
> but the callback in aio (Posix) is done by creating a new thread.
>From the Microsoft documentation of ReadFileEx (a Windows API function):
"If the function succeeds, and the file reading operation completes, but the
calling thread is not in an alertable wait state, the system queues the
completion routine call, holding the call until the calling thread enters an
alertable wait state."
Very simply the calling thread starts off the read operation, and then
either polls the i/o state or waits. In that wait operation lies the call
to the i/o
completion routine (the callback), which is called on this thread.
>From the caller's point of view there's only one thread.
However, the abstraction involved in waiting on completion is the same as
waiting for a thread, so the i/o operation is perhaps best modelled as
having at least part of the interface of a thread (but this just gut
feeling).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk