11 Event-based concurrency

 

In this chapter:

  • You learn how to overcome the difficulties of the inefficient busy-waiting approach from Chapter 10
  • You learn more about synchronization in message-passing IPC
  • You learn about event-based concurrency
  • You learn the reactor design pattern

Concurrency is a critical aspect of modern software development, allowing applications to perform multiple tasks simultaneously and maximize hardware utilization. While traditional thread/process-based concurrency is a well-known technique, it is not always the best approach for every application. In fact, for high-load I/O-bound applications, event-based concurrency is often a more effective solution.

Event-based concurrency involves organizing an application around events or messages rather than threads or processes. When an event occurs, the application responds by invoking a handler function, which performs the necessary processing. This approach has several advantages over traditional concurrency models, including lower resource usage, better scalability, and improved responsiveness.

Real-world examples of event-based concurrency can often be found in many high-performance applications, such as web servers, messaging systems, and gaming platforms. For instance, a web server can use event-based concurrency to handle a large number of simultaneous connections with minimal resource consumption, while a messaging system can use it to efficiently process a high volume of messages.

Events

Callbacks

Event loop

I/O multiplexing

Event-driven pizza server

Reactor pattern

Synchronization in message passing

I/O models

Synchronous blocking model

Synchronous nonblocking model

Asynchronous blocking model