In the previous recipe, we saw how to create shared memory and how to place some objects in it. Now, it's time to do something useful. Let's take an example from the Making a work_queue recipe in Chapter 5, Multithreading, and make it work for multiple processes. At the end of this example, we'll get a class that may store different tasks and pass them between processes.
This recipe uses techniques from the previous one. You will also need to read the Making a work_queue recipe in Chapter 5, Multithreading, and get its main idea. The example requires linking against the runtime library rt
on some platforms.
It is considered that spawning separate sub-processes instead of threads makes a program more reliable, because termination of a sub-process does not terminate the main process. We won't argue with that assumption here, and just see how data sharing between processes can be implemented.
- A lot of headers are required for this...