Reading C# documentation, I wonder how one can know if the IO is blocking or not. For example the BinaryWriter.Write method, I cannot find any information on the documentation on whether the method is blocking.
From MSDN, the return value of connect(): On a blocking socket, the return value indicates success or failure of the connection attempt. With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR , and WSAGetLastError() will return WSAEWOULDBLOCK.
Blocking vs. Java IO's various streams are blocking. It means when the thread invoke a write() or read(), then the thread is blocked until there is some data available for read, or the data is fully written. Non blocking IO does not wait for the data to be read or write before returning.
The event loop is what allows Node. js to perform non-blocking I/O operations despite the fact that JavaScript is single-threaded. The loop, which runs on the same thread as the JavaScript code, grabs a task from the code and executes it.
"Blocking" simply means a function will wait until a certain event happens. "Non blocking" means the function will never wait for something to happen, it will just return straight away, and wait until later to complete the action.
BinaryWriter.Write
only returns when its work is completed. That makes it blocking. The waiting time is potentially unbounded.
Asynchronous methods are usually easy to spot because they return Task
or IAsyncResult
(which corresponds to the old APM pattern). They also are named appropriately (BeginXxx
or XxxAsync
). When such a method returns you do not have the result yet. That indicates to you that the computation is still unfinished.
The docs call this property out for async methods. Because almost all methods are blocking and synchronous (e.g. all string methods) this behavior not noted in the docs. It is the default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With