Sometimes, we write programs that communicate with each other a lot. When programs are run on different machines, using sockets is the most common technique for communication. But if multiple processes run on a single machine, we can do much better!
Let's take a look at how to make a single memory fragment available from different processes using the Boost.Interprocess
library.
Basic knowledge of C++ is required for this recipe. Knowledge of atomic variables is also required (take a look at the See also section for more information about atomics). Some platforms require linking against the runtime library rt
.
In this example, we will be sharing a single atomic variable between processes, making it increment when a new process starts and decrement when the process terminates:
- We need to include the following header for interprocess communications:
#include <boost/interprocess/managed_shared_memory.hpp>
- Following...