Another Problem: State Management
Explore the complexities of state management in event-based concurrency, focusing on asynchronous I/O and how to handle program state without relying on thread stacks. Learn about continuations as a solution and the role of UNIX signals in process communication and control.
We'll cover the following...
Another issue with the event-based approach is that such code is generally more complicated to write than traditional thread-based code. The reason is that when an event handler issues an asynchronous I/O, it must package up some program state for the next event handler to use when the I/O finally completes. This additional work is not needed in thread-based programs, as the state the program needs is on the stack of the thread.
An example
To make this point more concrete, let’s look at a simple example in which a thread-based server needs to read from a file descriptor (fd) and, once complete, write the data that it read ...