Blocking vs Non-blocking
Blocking and Non-blocking
β From the perspective of control
Blocking
Waiting until I/O finishes
why?
Because the function does not return until it finishes
The user process
suspends work and waitsuntil the kernel completes the taskSince I/O operations barely use CPU resources, the blocking approach results in
significant CPU resource wasteBlocking is done for synchronization
Blocking vs Synchronous
If it is
not mandatory to stay in the wait queuewhile waiting for the system's return, it is synchronousIf it is
mandatory to stay in the wait queuewhile waiting for the system's return, it is blocking
Non-blocking
Created to overcome the inefficiency of the blocking approach
Does not suspend the user process's work while I/O operations are in progress
When the user process makes a function call (
system call) to the kernel for I/O processing, the kernel returns a result immediately regardless of the function's progressThe result returned at this point is the
datathat can be retrieved at that momentInitially there may be no data to retrieve, but over time, data becomes available
Problem
The client must continuously
check whetherthe returned value has reached the desired size (polling)In the process of checking whether the returned data is ready (whether it has reached the desired value), if numerous client requests occur simultaneously, it can place
a significant burden on the CPU
Non-blocking vs Asynchronous
If the
result (data) is returned along withthe system call return, it is non-blockingIf the
result (data) is not returned along withthe system call return, it is asynchronousSummary
The asynchronous approach delivers data through callback functions, events, or signals
The non-blocking approach includes data with every system call return, and checks whether the returned data has fully arrived as requested
Blocking vs Non-blocking
If the application
enters the OS wait queueduring execution and sends a responseafter the system call for the request is completed, it isblockingIf the application
does not enter the OS wait queueduring execution and sends aresponse immediatelyregardless of execution status, it isnon-blocking
Summary
Blocking vs Non-Blocking β
From the perspective of controlSync vs Async β
From the perspective of order and result (processing)
Last updated