Studying Inter Processes Communication in Operating System, I've discovered that asynchronous communication can be built on top of synchronous communication. But, it's not clear to me how can it be done. Can you explain to me ? :)
-
Run your synchronous operation on its own thread, or sign it up as a continuation on the same thread. – Robert Harvey Feb 18 '18 at 17:29
1 Answers
First, I think we need a good understanding of the terms Synchronous and Asynchronous.
These terms refer not to a message communicated between processes but to the model of sending or receiving such message relative to computing going on in the process. Thus, the same communication — the same exact message — could be async for one process and sync for the other.
Synchronous I/O is also called blocking I/O; asynchronous I/O is non-blocking I/O. Again these terms highlight the approach to sending/receiving relative to the internal computing of a sending or receiving process (rather than describing the communication itself).
If you are using synchronous I/O to send or receive a message, then the process will block until the message is fully sent or received. Thus, it would appear to be very difficult to convert this to an asynchronous approach.
However, you can create a new thread just for performing an I/O operation, while the existing main thread or threads continue(s) to execute. Doing this provides a sacrificial thread that will block on the synchronous I/O request, while the other threads can continue to run. Thus, the I/O operation would appear asynchronous to the main/other threads, despite using blocking I/O in the new thread.
(In the absence of threads, you could do similar with multiple processes.)
- 33,747