Understanding Blocking, Non‑Blocking, Multiplexed & Asynchronous I/O Models

This article explains the four main I/O models—blocking, non‑blocking, multiplexed (event‑driven) and asynchronous—detailing their mechanisms, kernel interactions, performance implications, and how they differ in handling data readiness for network programming.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
Understanding Blocking, Non‑Blocking, Multiplexed & Asynchronous I/O Models

Preface

IO is an important part of computer systems. Different IO devices have different characteristics such as data rate, transfer unit, and data representation, making a unified I/O method difficult.

There are two IO operation types: synchronous IO and asynchronous IO . Synchronous IO requires waiting for the operation to finish before control returns to the user process, while asynchronous IO returns control immediately without waiting.

Blocking I/O Model

In Linux, sockets are blocking by default. A typical read operation flow is shown.

Blocking and non‑blocking describe how a user thread calls kernel IO: blocking means the IO must finish before returning to user space; non‑blocking returns immediately with a status value.

When an application calls recvfrom, the kernel first prepares data. If the data is not yet ready, the kernel waits and the user process is blocked. Once the data is ready, it is copied to user memory and the kernel returns, unblocking the process. Thus both stages of IO are blocked.

Most socket interfaces are blocking; they do not return until the call completes or times out. This can cause a thread to be unable to perform other work while waiting.

Non‑Blocking I/O Model

In Linux, a socket can be set to non‑blocking. When a non‑blocking socket performs a read, if data is not ready the call returns immediately with an error instead of blocking.

From the user process perspective, it receives an immediate result and can retry later. Once data becomes ready, a subsequent read copies the data and returns successfully.

Therefore, non‑blocking I/O requires the process to actively poll the kernel for readiness. The function fcntl(fd, F_SETFL, O_NONBLOCK) can set a descriptor to non‑blocking.

recv return values:

Return value > 0: data received, the value is the number of bytes.

Return value 0: connection has been closed normally.

Return value -1 with errno equal to EAGAIN: the operation has not completed yet.

Return value -1 with errno not equal to EAGAIN: a system error occurred.

Continuously looping recv in a single thread can consume high CPU and is not recommended; more efficient mechanisms like select or epoll should be used.

Multiplexed I/O Model

Multiplexed I/O, also called event‑driven I/O, uses a function that polls multiple sockets and notifies the user process when data arrives.

When the user calls select, the process blocks while the kernel monitors all sockets. When any socket has data ready, select returns and the process reads the data.

This model uses two system calls (select and read) compared to one in blocking I/O, but its advantage is handling many connections simultaneously.

Asynchronous I/O Model

After the user initiates a read, it can continue other work. The kernel immediately returns, then later copies the data when ready and sends a signal to the process indicating completion.

In contrast, non‑blocking I/O returns immediately only when data is not ready, and the process must poll again. Asynchronous I/O avoids any blocking during the entire operation.

Conclusion

After studying, the differences between non‑blocking I/O and asynchronous I/O become clear. Non‑blocking requires active checking, while asynchronous delegates the whole operation to the kernel and receives a completion signal.

Understanding I/O fundamentals is essential for backend development; further study of Unix network programming is recommended.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AsynchronousI/ONetwork programmingMultiplexingNon-blockingBlocking
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.