If you need to share data between multiple processes, take a look at the forks and forks::shared modules (as well as the threads and threads::shared modules).
The semantics are different than what you're doing now, and there is some extra overhead, but I've been using both threads and forks for a couple years now with no problem, in production environments no less.