1 of 10

Read / Write

Read / Write

(O_NONBLOCK)

AIO

I/O Multiplexing

(select / poll)

Asynchronous

Synchronous

Blocking

Non-Blocking

v20190328

2 of 10

t

Application

Kernel

recvfrom

system call

(context switch)

no datagram ready

wait for data

datagram ready

copy datagram

copy complete

copy data from

kernel to user

process datagram

process blocks in call to recvfrom

Fig 6.1 Blocking I/O Model

return OK

Data from kernel space to user space

v20190328

3 of 10

system call

(context switch)

t

Application

Kernel

recvfrom

no datagram ready

wait for data

datagram ready

copy datagram

copy complete

copy data from

kernel to user

process datagram

process repeatedly calls recvfrom waiting for an OK return (polling)

Fig 6.2 Nonblocking I/O Model

return OK

EWOULDLOCK

EAGAIN

system call

(context switch)

EWOULDLOCK

EAGAIN

recvfrom

v20190328

4 of 10

t

Application

Kernel

select

no datagram ready

wait for data

datagram ready

copy datagram

copy complete

copy data from

kernel to user

process datagram

process blocks in call to select,

waiting for one of passibly many sockets to become readable

Fig 6.3 I/O Multiplexing Model

return OK

return readable

recvfrom

system call

process blocks while data

copied into application buffer

system call

(context switch)

v20190328

5 of 10

sigaction

system call

t

Application

Kernel

establish SIGIO signal handler

wait for data

datagram ready

copy datagram

copy complete

copy data from

kernel to user

process datagram

process continuus executing

Fig 6.4 Signal-Driven I/O Model

return OK

deliver SIGIO

recvfrom

system call

process blocks while data

copied into application buffer

return

signal handler

v20220601

6 of 10

t

Application

Kernel

aio_read

no datagram ready

wait for data

datagram ready

copy datagram

copy complete

copy data from

kernel to user

singal handler

process datagram

process continues executing

Fig 6.5 Asynchronous I/O model

deliver signal

specified in aio_read

return

system call

(context switch)

v20190328

7 of 10

Fig 6.6 Comparsion of the five I/O models

blocking

nonblocking

I/O multiplexing

signal-driven I/O

asynchronous I/O

initiate

complete

blocked

check

complete

blocked

check

complete

blocked

notifation initiate

complete

initiate

notification

check

check

check

wait for data

check

check

ready initiate

copy data from kernel to user

1st phase handled differently,

2nd phase handled the same

(blocked in call to recvfrom)

blocked

blocked

handles both phases

v20220601

8 of 10

ref

  • https://itimetraveler.github.io/2018/05/15/%E3%80%90Java%E3%80%91NIO%E7%9A%84%E7%90%86%E8%A7%A3/

9 of 10

backup

10 of 10

recvfrom

no datagram ready

system call

Application

Kernel

datagram ready

copy datagram

copy complete

process datagram

return OK

process blocks in

call to recvfrom

Fig 6.1 Blocking I/O model

wait for data

copy data from

kernel to user