<s>
In	O
computer	O
science	O
,	O
asynchronous	B-Architecture
I/O	I-Architecture
(	O
also	O
non-sequential	O
I/O	B-General_Concept
)	O
is	O
a	O
form	O
of	O
input/output	B-General_Concept
processing	I-General_Concept
that	O
permits	O
other	O
processing	O
to	O
continue	O
before	O
the	O
transmission	O
has	O
finished	O
.	O
</s>
<s>
A	O
name	O
used	O
for	O
asynchronous	B-Architecture
I/O	I-Architecture
in	O
the	O
Windows	B-Application
API	B-General_Concept
is	O
overlapped	B-Operating_System
I/O	I-Operating_System
.	O
</s>
<s>
Input	B-General_Concept
and	I-General_Concept
output	I-General_Concept
(	O
I/O	B-General_Concept
)	O
operations	O
on	O
a	O
computer	O
can	O
be	O
extremely	O
slow	O
compared	O
to	O
the	O
processing	O
of	O
data	O
.	O
</s>
<s>
An	O
I/O	B-General_Concept
device	I-General_Concept
can	O
incorporate	O
mechanical	O
devices	O
that	O
must	O
physically	O
move	O
,	O
such	O
as	O
a	O
hard	O
drive	O
seeking	O
a	O
track	O
to	O
read	O
or	O
write	O
;	O
this	O
is	O
often	O
orders	B-Device
of	I-Device
magnitude	I-Device
slower	O
than	O
the	O
switching	O
of	O
electric	O
current	O
.	O
</s>
<s>
A	O
simple	O
approach	O
to	O
I/O	B-General_Concept
would	O
be	O
to	O
start	O
the	O
access	O
and	O
then	O
wait	O
for	O
it	O
to	O
complete	O
.	O
</s>
<s>
But	O
such	O
an	O
approach	O
(	O
called	O
synchronous	B-Architecture
I/O	I-Architecture
,	O
or	O
blocking	B-Architecture
I/O	I-Architecture
)	O
would	O
block	O
the	O
progress	O
of	O
a	O
program	O
while	O
the	O
communication	O
is	O
in	O
progress	O
,	O
leaving	O
system	B-General_Concept
resources	I-General_Concept
idle	O
.	O
</s>
<s>
When	O
a	O
program	O
makes	O
many	O
I/O	B-General_Concept
operations	I-General_Concept
(	O
such	O
as	O
a	O
program	O
mainly	O
or	O
largely	O
dependent	O
on	O
user	B-General_Concept
input	I-General_Concept
)	O
,	O
this	O
means	O
that	O
the	O
processor	O
can	O
spend	O
almost	O
all	O
of	O
its	O
time	O
idle	O
waiting	O
for	O
I/O	B-General_Concept
operations	I-General_Concept
to	O
complete	O
.	O
</s>
<s>
Alternatively	O
,	O
it	O
is	O
possible	O
to	O
start	O
the	O
communication	O
and	O
then	O
perform	O
processing	O
that	O
does	O
not	O
require	O
that	O
the	O
I/O	B-General_Concept
be	O
completed	O
.	O
</s>
<s>
This	O
approach	O
is	O
called	O
asynchronous	B-Architecture
input/output	I-Architecture
.	O
</s>
<s>
Any	O
task	O
that	O
depends	O
on	O
the	O
I/O	B-General_Concept
having	O
completed	O
(	O
this	O
includes	O
both	O
using	O
the	O
input	O
values	O
and	O
critical	O
operations	O
that	O
claim	O
to	O
assure	O
that	O
a	O
write	O
operation	O
has	O
been	O
completed	O
)	O
still	O
needs	O
to	O
wait	O
for	O
the	O
I/O	B-General_Concept
operation	I-General_Concept
to	O
complete	O
,	O
and	O
thus	O
is	O
still	O
blocked	O
,	O
but	O
other	O
processing	O
that	O
does	O
not	O
have	O
a	O
dependency	O
on	O
the	O
I/O	B-General_Concept
operation	I-General_Concept
can	O
continue	O
.	O
</s>
<s>
Many	O
operating	B-General_Concept
system	I-General_Concept
functions	O
exist	O
to	O
implement	O
asynchronous	B-Architecture
I/O	I-Architecture
at	O
many	O
levels	O
.	O
</s>
<s>
In	O
fact	O
,	O
one	O
of	O
the	O
main	O
functions	O
of	O
all	O
but	O
the	O
most	O
rudimentary	O
of	O
operating	B-General_Concept
systems	I-General_Concept
is	O
to	O
perform	O
at	O
least	O
some	O
form	O
of	O
basic	O
asynchronous	B-Architecture
I/O	I-Architecture
,	O
though	O
this	O
may	O
not	O
be	O
particularly	O
apparent	O
to	O
the	O
user	O
or	O
the	O
programmer	O
.	O
</s>
<s>
In	O
the	O
simplest	O
software	O
solution	O
,	O
the	O
hardware	O
device	O
status	O
is	O
polled	B-General_Concept
at	O
intervals	O
to	O
detect	O
whether	O
the	O
device	O
is	O
ready	O
for	O
its	O
next	O
operation	O
.	O
</s>
<s>
(	O
For	O
example	O
,	O
the	O
CP/M	B-Application
operating	I-Application
system	I-Application
was	O
built	O
this	O
way	O
.	O
</s>
<s>
Its	O
system	B-Operating_System
call	I-Operating_System
semantics	O
did	O
not	O
require	O
any	O
more	O
elaborate	O
I/O	B-General_Concept
structure	O
than	O
this	O
,	O
though	O
most	O
implementations	O
were	O
more	O
complex	O
,	O
and	O
thereby	O
more	O
efficient	O
.	O
)	O
</s>
<s>
Direct	B-General_Concept
memory	I-General_Concept
access	I-General_Concept
(	O
DMA	B-General_Concept
)	O
can	O
greatly	O
increase	O
the	O
efficiency	O
of	O
a	O
polling-based	O
system	O
,	O
and	O
hardware	O
interrupts	B-Application
can	O
eliminate	O
the	O
need	O
for	O
polling	B-General_Concept
entirely	O
.	O
</s>
<s>
Multitasking	B-Operating_System
operating	I-Operating_System
systems	I-Operating_System
can	O
exploit	O
the	O
functionality	O
provided	O
by	O
hardware	O
interrupts	B-Application
,	O
whilst	O
hiding	O
the	O
complexity	O
of	O
interrupt	B-Application
handling	I-Application
from	O
the	O
user	O
.	O
</s>
<s>
Spooling	B-Device
was	O
one	O
of	O
the	O
first	O
forms	O
of	O
multitasking	B-Operating_System
designed	O
to	O
exploit	O
asynchronous	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
Finally	O
,	O
multithreading	B-Operating_System
and	O
explicit	O
asynchronous	B-Architecture
I/O	I-Architecture
APIs	B-General_Concept
within	O
user	O
processes	O
can	O
exploit	O
asynchronous	B-Architecture
I/O	I-Architecture
further	O
,	O
at	O
the	O
cost	O
of	O
extra	O
software	O
complexity	O
.	O
</s>
<s>
Asynchronous	B-Architecture
I/O	I-Architecture
is	O
used	O
to	O
improve	O
energy	O
efficiency	O
,	O
and	O
in	O
some	O
cases	O
,	O
throughput	O
.	O
</s>
<s>
Forms	O
of	O
I/O	B-General_Concept
and	O
examples	O
of	O
POSIX	O
functions	O
:	O
</s>
<s>
All	O
forms	O
of	O
asynchronous	B-Architecture
I/O	I-Architecture
open	O
applications	O
up	O
to	O
potential	O
resource	O
conflicts	O
and	O
associated	O
failure	O
.	O
</s>
<s>
Careful	O
programming	O
(	O
often	O
using	O
mutual	B-Operating_System
exclusion	I-Operating_System
,	O
semaphores	B-Operating_System
,	O
etc	O
.	O
)	O
</s>
<s>
When	O
exposing	O
asynchronous	B-Architecture
I/O	I-Architecture
to	O
applications	O
there	O
are	O
a	O
few	O
broad	O
classes	O
of	O
implementation	O
.	O
</s>
<s>
The	O
form	O
of	O
the	O
API	B-General_Concept
provided	O
to	O
the	O
application	O
does	O
not	O
necessarily	O
correspond	O
with	O
the	O
mechanism	O
actually	O
provided	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
;	O
emulations	O
are	O
possible	O
.	O
</s>
<s>
Many	O
operating	B-General_Concept
systems	I-General_Concept
provide	O
more	O
than	O
one	O
of	O
these	O
mechanisms	O
,	O
it	O
is	O
possible	O
that	O
some	O
may	O
provide	O
all	O
of	O
them	O
.	O
</s>
<s>
Available	O
in	O
early	O
Unix	B-Application
.	O
</s>
<s>
In	O
a	O
multitasking	B-Operating_System
operating	I-Operating_System
system	I-Operating_System
,	O
processing	O
can	O
be	O
distributed	O
across	O
different	O
processes	O
,	O
which	O
run	O
independently	O
,	O
have	O
their	O
own	O
memory	O
,	O
and	O
process	B-Operating_System
their	O
own	O
I/O	B-General_Concept
flows	O
;	O
these	O
flows	O
are	O
typically	O
connected	O
in	O
pipelines	B-Operating_System
.	O
</s>
<s>
It	O
also	O
assumes	O
that	O
the	O
individual	O
processes	O
can	O
operate	O
independently	O
,	O
apart	O
from	O
processing	O
each	O
other	O
's	O
I/O	B-General_Concept
;	O
if	O
they	O
need	O
to	O
communicate	O
in	O
other	O
ways	O
,	O
coordinating	O
them	O
can	O
become	O
difficult	O
.	O
</s>
<s>
An	O
extension	O
of	O
this	O
approach	O
is	O
dataflow	B-Application
programming	I-Application
,	O
which	O
allows	O
more	O
complicated	O
networks	O
than	O
just	O
the	O
chains	O
that	O
pipes	B-Operating_System
support	O
.	O
</s>
<s>
Polling	B-General_Concept
provides	O
non-blocking	O
synchronous	O
API	B-General_Concept
which	O
may	O
be	O
used	O
to	O
implement	O
some	O
asynchronous	O
API	B-General_Concept
.	O
</s>
<s>
Available	O
in	O
traditional	B-Application
Unix	I-Application
and	O
Windows	B-Application
.	O
</s>
<s>
Its	O
major	O
problem	O
is	O
that	O
it	O
can	O
waste	O
CPU	O
time	O
polling	B-General_Concept
repeatedly	O
when	O
there	O
is	O
nothing	O
else	O
for	O
the	O
issuing	O
process	B-Operating_System
to	O
do	O
,	O
reducing	O
the	O
time	O
available	O
for	O
other	O
processes	O
.	O
</s>
<s>
Also	O
,	O
because	O
a	O
polling	B-General_Concept
application	O
is	O
essentially	O
single-threaded	B-Operating_System
it	O
may	O
be	O
unable	O
to	O
fully	O
exploit	O
I/O	B-General_Concept
parallelism	O
that	O
the	O
hardware	O
is	O
capable	O
of	O
.	O
</s>
<s>
Available	O
in	O
BSD	B-Operating_System
Unix	I-Operating_System
,	O
and	O
almost	O
anything	O
else	O
with	O
a	O
TCP/IP	B-Protocol
protocol	I-Protocol
stack	I-Protocol
that	O
either	O
utilizes	O
or	O
is	O
modeled	O
after	O
the	O
BSD	B-Operating_System
implementation	O
.	O
</s>
<s>
A	O
variation	O
on	O
the	O
theme	O
of	O
polling	B-General_Concept
,	O
a	O
select	B-Language
loop	O
uses	O
the	O
select	B-Language
system	B-Operating_System
call	I-Operating_System
to	O
sleep	B-Operating_System
until	O
a	O
condition	O
occurs	O
on	O
a	O
file	B-Application
descriptor	I-Application
(	O
e.g.	O
,	O
when	O
data	O
is	O
available	O
for	O
reading	O
)	O
,	O
a	O
timeout	O
occurs	O
,	O
or	O
a	O
signal	B-Operating_System
is	O
received	O
(	O
e.g.	O
,	O
when	O
a	O
child	O
process	B-Operating_System
dies	O
)	O
.	O
</s>
<s>
By	O
examining	O
the	O
return	O
parameters	O
of	O
the	O
select	B-Language
call	O
,	O
the	O
loop	O
finds	O
out	O
which	O
file	B-Application
descriptor	I-Application
has	O
changed	O
and	O
executes	O
the	O
appropriate	O
code	O
.	O
</s>
<s>
Often	O
,	O
for	O
ease	O
of	O
use	O
,	O
the	O
select	B-Language
loop	O
is	O
implemented	O
as	O
an	O
event	B-General_Concept
loop	I-General_Concept
,	O
perhaps	O
using	O
callback	O
functions	O
;	O
the	O
situation	O
lends	O
itself	O
particularly	O
well	O
to	O
event-driven	B-Application
programming	I-Application
.	O
</s>
<s>
While	O
this	O
method	O
is	O
reliable	O
and	O
relatively	O
efficient	O
,	O
it	O
depends	O
heavily	O
on	O
the	O
Unix	B-Application
paradigm	O
that	O
"	O
everything	B-Application
is	I-Application
a	I-Application
file	I-Application
"	O
;	O
any	O
blocking	B-Architecture
I/O	I-Architecture
that	O
does	O
not	O
involve	O
a	O
file	B-Application
descriptor	I-Application
will	O
block	O
the	O
process	B-Operating_System
.	O
</s>
<s>
The	O
select	B-Language
loop	O
also	O
relies	O
on	O
being	O
able	O
to	O
involve	O
all	O
I/O	B-General_Concept
in	O
the	O
central	O
select	B-Language
call	O
;	O
libraries	O
that	O
conduct	O
their	O
own	O
I/O	B-General_Concept
are	O
particularly	O
problematic	O
in	O
this	O
respect	O
.	O
</s>
<s>
An	O
additional	O
potential	O
problem	O
is	O
that	O
the	O
select	B-Language
and	O
the	O
I/O	B-General_Concept
operations	I-General_Concept
are	O
still	O
sufficiently	O
decoupled	O
that	O
select	B-Language
's	O
result	O
may	O
effectively	O
be	O
a	O
lie	O
:	O
if	O
two	O
processes	O
are	O
reading	O
from	O
a	O
single	O
file	B-Application
descriptor	I-Application
(	O
arguably	O
bad	O
design	O
)	O
the	O
select	B-Language
may	O
indicate	O
the	O
availability	O
of	O
read	O
data	O
that	O
has	O
disappeared	O
by	O
the	O
time	O
that	O
the	O
read	O
is	O
issued	O
,	O
thus	O
resulting	O
in	O
blocking	O
;	O
if	O
two	O
processes	O
are	O
writing	O
to	O
a	O
single	O
file	B-Application
descriptor	I-Application
(	O
not	O
that	O
uncommon	O
)	O
the	O
select	B-Language
may	O
indicate	O
immediate	O
writability	O
yet	O
the	O
write	O
may	O
still	O
block	O
,	O
because	O
a	O
buffer	O
has	O
been	O
filled	O
by	O
the	O
other	O
process	B-Operating_System
in	O
the	O
interim	O
,	O
or	O
due	O
to	O
the	O
write	O
being	O
too	O
large	O
for	O
the	O
available	O
buffer	O
or	O
in	O
other	O
ways	O
unsuitable	O
to	O
the	O
recipient	O
.	O
</s>
<s>
The	O
select	B-Language
loop	O
does	O
not	O
reach	O
the	O
ultimate	O
system	O
efficiency	O
possible	O
with	O
,	O
say	O
,	O
the	O
completion	O
queues	B-Device
method	O
,	O
because	O
the	O
semantics	O
of	O
the	O
select	B-Language
call	O
,	O
allowing	O
as	O
it	O
does	O
for	O
per-call	O
tuning	O
of	O
the	O
acceptable	O
event	O
set	O
,	O
consumes	O
some	O
amount	O
of	O
time	O
per	O
invocation	O
traversing	O
the	O
selection	O
array	O
.	O
</s>
<s>
This	O
creates	O
little	O
overhead	O
for	O
user	O
applications	O
that	O
might	O
have	O
open	O
one	O
file	B-Application
descriptor	I-Application
for	O
the	O
windowing	B-Application
system	I-Application
and	O
a	O
few	O
for	O
open	O
files	O
,	O
but	O
becomes	O
more	O
of	O
a	O
problem	O
as	O
the	O
number	O
of	O
potential	O
event	O
sources	O
grows	O
,	O
and	O
can	O
hinder	O
development	O
of	O
many-client	O
server	O
applications	O
,	O
as	O
in	O
the	O
C10k	B-Protocol
problem	I-Protocol
;	O
other	O
asynchronous	O
methods	O
may	O
be	O
noticeably	O
more	O
efficient	O
in	O
such	O
cases	O
.	O
</s>
<s>
Some	O
Unixes	B-Application
provide	O
system-specific	O
calls	O
with	O
better	O
scaling	O
;	O
for	O
example	O
,	O
epoll	B-Application
in	O
Linux	B-Operating_System
(	O
that	O
fills	O
the	O
return	O
selection	O
array	O
with	O
only	O
those	O
event	O
sources	O
on	O
which	O
an	O
event	O
has	O
occurred	O
)	O
,	O
kqueue	B-Application
in	O
FreeBSD	B-Operating_System
,	O
and	O
event	O
ports	O
(	O
and	O
/dev/poll	O
)	O
in	O
Solaris	B-Application
.	O
</s>
<s>
SVR3	B-Operating_System
Unix	B-Application
provided	O
the	O
poll	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
Arguably	O
better-named	O
than	O
select	B-Language
,	O
for	O
the	O
purposes	O
of	O
this	O
discussion	O
it	O
is	O
essentially	O
the	O
same	O
thing	O
.	O
</s>
<s>
SVR4	O
Unixes	B-Application
(	O
and	O
thus	O
POSIX	O
)	O
offer	O
both	O
calls	O
.	O
</s>
<s>
Available	O
in	O
BSD	B-Operating_System
and	O
POSIX	O
Unix	B-Application
.	O
</s>
<s>
I/O	B-General_Concept
is	O
issued	O
asynchronously	O
,	O
and	O
when	O
it	O
is	O
completed	O
a	O
signal	B-Operating_System
(	O
interrupt	B-Application
)	O
is	O
generated	O
.	O
</s>
<s>
As	O
in	O
low-level	O
kernel	B-Operating_System
programming	O
,	O
the	O
facilities	O
available	O
for	O
safe	O
use	O
within	O
the	O
signal	B-Operating_System
handler	I-Operating_System
are	O
limited	O
,	O
and	O
the	O
main	O
flow	O
of	O
the	O
process	B-Operating_System
could	O
have	O
been	O
interrupted	O
at	O
nearly	O
any	O
point	O
,	O
resulting	O
in	O
inconsistent	O
data	O
structures	O
as	O
seen	O
by	O
the	O
signal	B-Operating_System
handler	I-Operating_System
.	O
</s>
<s>
The	O
signal	B-Operating_System
handler	I-Operating_System
is	O
usually	O
not	O
able	O
to	O
issue	O
further	O
asynchronous	B-Architecture
I/O	I-Architecture
by	O
itself	O
.	O
</s>
<s>
The	O
signal	B-Operating_System
approach	O
,	O
though	O
relatively	O
simple	O
to	O
implement	O
within	O
the	O
OS	O
,	O
brings	O
to	O
the	O
application	O
program	O
the	O
unwelcome	O
baggage	O
associated	O
with	O
writing	O
an	O
operating	B-General_Concept
system	I-General_Concept
's	O
kernel	B-Operating_System
interrupt	B-Application
system	O
.	O
</s>
<s>
Its	O
worst	O
characteristic	O
is	O
that	O
every	O
blocking	O
(	O
synchronous	O
)	O
system	B-Operating_System
call	I-Operating_System
is	O
potentially	O
interruptible	O
;	O
the	O
programmer	O
must	O
usually	O
incorporate	O
retry	O
code	O
at	O
each	O
call	O
.	O
</s>
<s>
Available	O
in	O
the	O
classic	B-Application
Mac	I-Application
OS	I-Application
,	O
VMS	B-Operating_System
and	O
Windows	B-Application
.	O
</s>
<s>
Bears	O
many	O
of	O
the	O
characteristics	O
of	O
the	O
signal	B-Operating_System
method	O
as	O
it	O
is	O
fundamentally	O
the	O
same	O
thing	O
,	O
though	O
rarely	O
recognized	O
as	O
such	O
.	O
</s>
<s>
The	O
difference	O
is	O
that	O
each	O
I/O	B-General_Concept
request	O
usually	O
can	O
have	O
its	O
own	O
completion	O
function	O
,	O
whereas	O
the	O
signal	B-Operating_System
system	O
has	O
a	O
single	O
callback	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
a	O
potential	O
problem	O
of	O
using	O
callbacks	O
is	O
that	O
stack	O
depth	O
can	O
grow	O
unmanageably	O
,	O
as	O
an	O
extremely	O
common	O
thing	O
to	O
do	O
when	O
one	O
I/O	B-General_Concept
is	O
finished	O
is	O
to	O
schedule	O
another	O
.	O
</s>
<s>
In	O
practice	O
,	O
however	O
,	O
this	O
is	O
generally	O
not	O
a	O
problem	O
because	O
the	O
new	O
I/O	B-General_Concept
will	O
itself	O
usually	O
return	O
as	O
soon	O
as	O
the	O
new	O
I/O	B-General_Concept
is	O
started	O
allowing	O
the	O
stack	O
to	O
be	O
'	O
unwound	O
 '	O
.	O
</s>
<s>
The	O
problem	O
can	O
also	O
be	O
prevented	O
by	O
avoiding	O
any	O
further	O
callbacks	O
,	O
by	O
means	O
of	O
a	O
queue	B-Device
,	O
until	O
the	O
first	O
callback	O
returns	O
.	O
</s>
<s>
Light-weight	B-Operating_System
processes	I-Operating_System
(	O
LWPs	O
)	O
or	O
threads	B-Operating_System
are	O
available	O
in	O
more	O
modern	O
Unixes	B-Application
,	O
originating	O
in	O
Plan	B-Operating_System
9	I-Operating_System
.	O
</s>
<s>
Like	O
the	O
process	B-Operating_System
method	O
,	O
but	O
without	O
the	O
data	O
isolation	O
that	O
hampers	O
coordination	O
of	O
the	O
flows	O
.	O
</s>
<s>
This	O
lack	O
of	O
isolation	O
introduces	O
its	O
own	O
problems	O
,	O
usually	O
requiring	O
kernel-provided	O
synchronization	O
mechanisms	O
and	O
thread-safe	B-Operating_System
libraries	O
.	O
</s>
<s>
Each	O
LWP	O
or	O
thread	B-Operating_System
itself	O
uses	O
traditional	O
blocking	O
synchronous	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
The	O
requisite	O
separate	O
per-thread	O
stack	O
may	O
preclude	O
large-scale	O
implementations	O
using	O
very	O
large	O
numbers	O
of	O
threads	B-Operating_System
.	O
</s>
<s>
This	O
approach	O
is	O
also	O
used	O
in	O
the	O
Erlang	B-Operating_System
programming	I-Operating_System
language	I-Operating_System
runtime	O
system	O
.	O
</s>
<s>
The	O
Erlang	B-Operating_System
virtual	B-Architecture
machine	I-Architecture
uses	O
asynchronous	B-Architecture
I/O	I-Architecture
using	O
a	O
small	O
pool	O
of	O
only	O
a	O
few	O
threads	B-Operating_System
or	O
sometimes	O
just	O
one	O
process	B-Operating_System
,	O
to	O
handle	O
I/O	B-General_Concept
from	O
up	O
to	O
millions	O
of	O
Erlang	B-Operating_System
processes	O
.	O
</s>
<s>
I/O	B-General_Concept
handling	O
in	O
each	O
process	B-Operating_System
is	O
written	O
mostly	O
using	O
blocking	O
synchronous	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
This	O
way	O
high	O
performance	O
of	O
asynchronous	B-Architecture
I/O	I-Architecture
is	O
merged	O
with	O
simplicity	O
of	O
normal	O
I/O	B-General_Concept
(	O
c.f.	O
</s>
<s>
the	O
Actor	B-Application
model	I-Application
)	O
.	O
</s>
<s>
Many	O
I/O	B-General_Concept
problems	O
in	O
Erlang	B-Operating_System
are	O
mapped	O
to	O
message	O
passing	O
,	O
which	O
can	O
be	O
easily	O
processed	O
using	O
built-in	O
selective	O
receive	O
.	O
</s>
<s>
Fibers	O
/	O
Coroutines	B-Architecture
can	O
be	O
viewed	O
as	O
a	O
similarly	O
lightweight	O
approach	O
to	O
do	O
asynchronous	B-Architecture
I/O	I-Architecture
outside	O
of	O
the	O
Erlang	B-Operating_System
runtime	O
system	O
,	O
although	O
they	O
do	O
not	O
provide	O
exactly	O
the	O
same	O
guarantees	O
as	O
Erlang	B-Operating_System
processes	O
.	O
</s>
<s>
Available	O
in	O
Microsoft	B-Application
Windows	I-Application
,	O
Solaris	B-Application
,	O
AmigaOS	B-Application
,	O
DNIX	B-Operating_System
and	O
Linux	B-Operating_System
(	O
using	O
io_uring	O
,	O
available	O
on	O
5.1	O
and	O
above	O
)	O
.	O
</s>
<s>
I/O	B-General_Concept
requests	O
are	O
issued	O
asynchronously	O
,	O
but	O
notifications	O
of	O
completion	O
are	O
provided	O
via	O
a	O
synchronizing	O
queue	B-Device
mechanism	O
in	O
the	O
order	O
they	O
are	O
completed	O
.	O
</s>
<s>
Usually	O
associated	O
with	O
a	O
state-machine	B-Architecture
structuring	O
of	O
the	O
main	O
process	B-Operating_System
(	O
event-driven	B-Application
programming	I-Application
)	O
,	O
which	O
can	O
bear	O
little	O
resemblance	O
to	O
a	O
process	B-Operating_System
that	O
does	O
not	O
use	O
asynchronous	B-Architecture
I/O	I-Architecture
or	O
that	O
uses	O
one	O
of	O
the	O
other	O
forms	O
,	O
hampering	O
code	O
reuse	O
.	O
</s>
<s>
Does	O
not	O
require	O
additional	O
special	O
synchronization	O
mechanisms	O
or	O
thread-safe	B-Operating_System
libraries	O
,	O
nor	O
are	O
the	O
textual	O
(	O
code	O
)	O
and	O
time	O
(	O
event	O
)	O
flows	O
separated	O
.	O
</s>
<s>
Available	O
in	O
VMS	B-Operating_System
and	O
AmigaOS	B-Application
(	O
often	O
used	O
in	O
conjunction	O
with	O
a	O
completion	B-Library
port	I-Library
)	O
.	O
</s>
<s>
Bears	O
many	O
of	O
the	O
characteristics	O
of	O
the	O
completion	O
queue	B-Device
method	O
,	O
as	O
it	O
is	O
essentially	O
a	O
completion	O
queue	B-Device
of	O
depth	O
one	O
.	O
</s>
<s>
To	O
simulate	O
the	O
effect	O
of	O
queue	B-Device
'	O
depth	O
 '	O
,	O
an	O
additional	O
event	O
flag	O
is	O
required	O
for	O
each	O
potential	O
unprocessed	O
(	O
but	O
completed	O
)	O
event	O
,	O
or	O
event	O
information	O
can	O
be	O
lost	O
.	O
</s>
<s>
Channel	B-Device
I/O	I-Device
is	O
designed	O
to	O
maximize	O
CPU	O
utilization	O
and	O
throughput	O
by	O
offloading	O
most	O
I/O	B-General_Concept
onto	O
a	O
coprocessor	O
.	O
</s>
<s>
The	O
coprocessor	O
has	O
onboard	O
DMA	B-General_Concept
,	O
handles	O
device	O
interrupts	B-Application
,	O
is	O
controlled	O
by	O
the	O
main	O
CPU	O
,	O
and	O
only	O
interrupts	B-Application
the	O
main	O
CPU	O
when	O
it	O
's	O
truly	O
necessary	O
.	O
</s>
<s>
This	O
architecture	O
also	O
supports	O
so-called	O
channel	O
programs	O
that	O
run	O
on	O
the	O
channel	O
processor	O
to	O
do	O
heavy	O
lifting	O
for	O
I/O	B-General_Concept
activities	O
and	O
protocols	O
.	O
</s>
<s>
Available	O
in	O
Windows	B-Device
Server	I-Device
2012	I-Device
and	O
Windows	B-Application
8	I-Application
.	O
</s>
<s>
Optimized	O
for	O
applications	O
that	O
process	B-Operating_System
large	O
numbers	O
of	O
small	O
messages	O
to	O
achieve	O
higher	O
I/O	B-General_Concept
operations	I-General_Concept
per	O
second	O
with	O
reduced	O
jitter	O
and	O
latency	O
.	O
</s>
<s>
The	O
vast	O
majority	O
of	O
general-purpose	O
computing	O
hardware	O
relies	O
entirely	O
upon	O
two	O
methods	O
of	O
implementing	O
asynchronous	B-Architecture
I/O	I-Architecture
:	O
polling	B-General_Concept
and	O
interrupts	B-Application
.	O
</s>
<s>
(	O
DMA	B-General_Concept
is	O
not	O
itself	O
another	O
independent	O
method	O
,	O
it	O
is	O
merely	O
a	O
means	O
by	O
which	O
more	O
work	O
can	O
be	O
done	O
per	O
poll	O
or	O
interrupt	B-Application
.	O
)	O
</s>
<s>
Pure	O
polling	B-General_Concept
systems	O
are	O
entirely	O
possible	O
,	O
small	O
microcontrollers	O
(	O
such	O
as	O
systems	O
using	O
the	O
PIC	B-Architecture
)	O
are	O
often	O
built	O
this	O
way	O
.	O
</s>
<s>
CP/M	B-Application
systems	O
could	O
also	O
be	O
built	O
this	O
way	O
(	O
though	O
rarely	O
were	O
)	O
,	O
with	O
or	O
without	O
DMA	B-General_Concept
.	O
</s>
<s>
Also	O
,	O
when	O
the	O
utmost	O
performance	O
is	O
necessary	O
for	O
only	O
a	O
few	O
tasks	O
,	O
at	O
the	O
expense	O
of	O
any	O
other	O
potential	O
tasks	O
,	O
polling	B-General_Concept
may	O
also	O
be	O
appropriate	O
as	O
the	O
overhead	O
of	O
taking	O
interrupts	B-Application
may	O
be	O
unwelcome	O
.	O
</s>
<s>
(	O
Servicing	O
an	O
interrupt	B-Application
requires	O
time	O
[	O
and	O
space ]	O
to	O
save	O
at	O
least	O
part	O
of	O
the	O
processor	O
state	O
,	O
along	O
with	O
the	O
time	O
required	O
to	O
resume	O
the	O
interrupted	O
task	O
.	O
)	O
</s>
<s>
Most	O
general-purpose	O
computing	O
systems	O
rely	O
heavily	O
upon	O
interrupts	B-Application
.	O
</s>
<s>
A	O
pure	O
interrupt	B-Application
system	O
may	O
be	O
possible	O
,	O
though	O
usually	O
some	O
component	O
of	O
polling	B-General_Concept
is	O
also	O
required	O
,	O
as	O
it	O
is	O
very	O
common	O
for	O
multiple	O
potential	O
sources	O
of	O
interrupts	B-Application
to	O
share	O
a	O
common	O
interrupt	B-Application
signal	B-Operating_System
line	O
,	O
in	O
which	O
case	O
polling	B-General_Concept
is	O
used	O
within	O
the	O
device	B-Application
driver	I-Application
to	O
resolve	O
the	O
actual	O
source	O
.	O
</s>
<s>
(	O
This	O
resolution	O
time	O
also	O
contributes	O
to	O
an	O
interrupt	B-Application
system	O
's	O
performance	O
penalty	O
.	O
</s>
<s>
Over	O
the	O
years	O
a	O
great	O
deal	O
of	O
work	O
has	O
been	O
done	O
to	O
try	O
to	O
minimize	O
the	O
overhead	O
associated	O
with	O
servicing	O
an	O
interrupt	B-Application
.	O
</s>
<s>
Current	O
interrupt	B-Application
systems	O
are	O
rather	O
lackadaisical	O
when	O
compared	O
to	O
some	O
highly	O
tuned	O
earlier	O
ones	O
,	O
but	O
the	O
general	O
increase	O
in	O
hardware	O
performance	O
has	O
greatly	O
mitigated	O
this	O
.	O
)	O
</s>
<s>
Hybrid	O
approaches	O
are	O
also	O
possible	O
,	O
wherein	O
an	O
interrupt	B-Application
can	O
trigger	O
the	O
beginning	O
of	O
some	O
burst	O
of	O
asynchronous	B-Architecture
I/O	I-Architecture
,	O
and	O
polling	B-General_Concept
is	O
used	O
within	O
the	O
burst	O
itself	O
.	O
</s>
<s>
This	O
technique	O
is	O
common	O
in	O
high-speed	O
device	B-Application
drivers	I-Application
,	O
such	O
as	O
network	O
or	O
disk	O
,	O
where	O
the	O
time	O
lost	O
in	O
returning	O
to	O
the	O
pre-interrupt	O
task	O
is	O
greater	O
than	O
the	O
time	O
until	O
the	O
next	O
required	O
servicing	O
.	O
</s>
<s>
(	O
Common	O
I/O	B-General_Concept
hardware	I-General_Concept
in	O
use	O
these	O
days	O
relies	O
heavily	O
upon	O
DMA	B-General_Concept
and	O
large	O
data	O
buffers	O
to	O
make	O
up	O
for	O
a	O
relatively	O
poorly-performing	O
interrupt	B-Application
system	O
.	O
</s>
<s>
These	O
characteristically	O
use	O
polling	B-General_Concept
inside	O
the	O
driver	O
loops	O
,	O
and	O
can	O
exhibit	O
tremendous	O
throughput	O
.	O
</s>
<s>
At	O
one	O
time	O
this	O
sort	O
of	O
hybrid	O
approach	O
was	O
common	O
in	O
disk	O
and	O
network	O
drivers	O
where	O
there	O
was	O
not	O
DMA	B-General_Concept
or	O
significant	O
buffering	O
available	O
.	O
</s>
<s>
Because	O
the	O
desired	O
transfer	O
speeds	O
were	O
faster	O
even	O
than	O
could	O
tolerate	O
the	O
minimum	O
four-operation	O
per-datum	O
loop	O
(	O
bit-test	O
,	O
conditional-branch-to-self	O
,	O
fetch	O
,	O
and	O
store	O
)	O
,	O
the	O
hardware	O
would	O
often	O
be	O
built	O
with	O
automatic	O
wait	B-Device
state	I-Device
generation	O
on	O
the	O
I/O	B-General_Concept
device	I-General_Concept
,	O
pushing	O
the	O
data	O
ready	O
poll	O
out	O
of	O
software	O
and	O
onto	O
the	O
processor	O
's	O
fetch	O
or	O
store	O
hardware	O
and	O
reducing	O
the	O
programmed	O
loop	O
to	O
two	O
operations	O
.	O
</s>
<s>
(	O
In	O
effect	O
using	O
the	O
processor	O
itself	O
as	O
a	O
DMA	B-General_Concept
engine	I-General_Concept
.	O
)	O
</s>
<s>
The	O
6502	B-General_Concept
processor	I-General_Concept
offered	O
an	O
unusual	O
means	O
to	O
provide	O
a	O
three-element	O
per-datum	O
loop	O
,	O
as	O
it	O
had	O
a	O
hardware	O
pin	O
that	O
,	O
when	O
asserted	O
,	O
would	O
cause	O
the	O
processor	O
's	O
Overflow	O
bit	O
to	O
be	O
set	O
directly	O
.	O
</s>
<s>
(	O
Obviously	O
one	O
would	O
have	O
to	O
take	O
great	O
care	O
in	O
the	O
hardware	O
design	O
to	O
avoid	O
overriding	O
the	O
Overflow	O
bit	O
outside	O
of	O
the	O
device	B-Application
driver	I-Application
!	O
)	O
</s>
<s>
Using	O
only	O
these	O
two	O
tools	O
(	O
polling	B-General_Concept
,	O
and	O
interrupts	B-Application
)	O
,	O
all	O
the	O
other	O
forms	O
of	O
asynchronous	B-Architecture
I/O	I-Architecture
discussed	O
above	O
may	O
be	O
(	O
and	O
in	O
fact	O
,	O
are	O
)	O
synthesized	O
.	O
</s>
<s>
In	O
an	O
environment	O
such	O
as	O
a	O
Java	B-Language
virtual	I-Language
machine	I-Language
(	O
JVM	B-Language
)	O
,	O
asynchronous	B-Architecture
I/O	I-Architecture
can	O
be	O
synthesized	O
even	O
though	O
the	O
environment	O
the	O
JVM	B-Language
is	O
running	O
in	O
may	O
not	O
offer	O
it	O
at	O
all	O
.	O
</s>
<s>
This	O
is	O
due	O
to	O
the	O
interpreted	O
nature	O
of	O
the	O
JVM	B-Language
.	O
</s>
<s>
The	O
JVM	B-Language
may	O
poll	O
(	O
or	O
take	O
an	O
interrupt	B-Application
)	O
periodically	O
to	O
institute	O
an	O
internal	O
flow	O
of	O
control	O
change	O
,	O
effecting	O
the	O
appearance	O
of	O
multiple	O
simultaneous	O
processes	O
,	O
at	O
least	O
some	O
of	O
which	O
presumably	O
exist	O
in	O
order	O
to	O
perform	O
asynchronous	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
That	O
,	O
in	O
fact	O
,	O
is	O
the	O
problem	O
with	O
using	O
polling	B-General_Concept
in	O
any	O
form	O
to	O
synthesize	O
a	O
different	O
form	O
of	O
asynchronous	B-Architecture
I/O	I-Architecture
.	O
</s>
<s>
Every	O
CPU	O
cycle	O
that	O
is	O
not	O
a	O
poll	O
represents	O
an	O
increase	O
in	O
latency	O
of	O
reaction	O
to	O
pending	O
I/O	B-General_Concept
.	O
</s>
<s>
(	O
This	O
is	O
why	O
hardware	O
interrupt	B-Application
systems	O
were	O
invented	O
in	O
the	O
first	O
place	O
.	O
)	O
</s>
<s>
The	O
trick	O
to	O
maximize	O
efficiency	O
is	O
to	O
minimize	O
the	O
amount	O
of	O
work	O
that	O
has	O
to	O
be	O
done	O
upon	O
reception	O
of	O
an	O
interrupt	B-Application
in	O
order	O
to	O
awaken	O
the	O
appropriate	O
application	O
.	O
</s>
<s>
Particularly	O
problematic	O
(	O
for	O
application	O
efficiency	O
)	O
are	O
the	O
exposed	O
polling	B-General_Concept
methods	O
,	O
including	O
the	O
select/poll	O
mechanisms	O
.	O
</s>
<s>
Though	O
the	O
underlying	O
I/O	B-General_Concept
events	O
they	O
are	O
interested	O
in	O
are	O
in	O
all	O
likelihood	O
interrupt-driven	O
,	O
the	O
interaction	O
to	O
this	O
mechanism	O
is	O
polled	B-General_Concept
and	O
can	O
consume	O
a	O
large	O
amount	O
of	O
time	O
in	O
the	O
poll	O
.	O
</s>
<s>
This	O
is	O
particularly	O
true	O
of	O
the	O
potentially	O
large-scale	O
polling	B-General_Concept
possible	O
through	O
select	B-Language
(	O
and	O
poll	O
)	O
.	O
</s>
<s>
Interrupts	B-Application
map	O
very	O
well	O
to	O
Signals	O
,	O
Callback	O
functions	O
,	O
Completion	O
Queues	B-Device
,	O
and	O
Event	O
flags	O
,	O
such	O
systems	O
can	O
be	O
very	O
efficient	O
.	O
</s>
<s>
Following	O
examples	O
shows	O
concepts	O
of	O
three	O
I/O	B-General_Concept
approaches	O
on	O
the	O
reading	O
operation	O
.	O
</s>
<s>
Here	O
is	O
the	O
example	O
with	O
Reactor	B-Operating_System
pattern	I-Operating_System
:	O
</s>
