I can't use mmap to share a Hash between processes

I am implementing a multi-process library that provides a data structure for shared memory.
But I am having trouble now, I modified the shared Hash object in the child process, but the parent process still has not read the changed value.

Sample code: https://play.crystal-lang.org/#/r/6n34

I don’t have much experience in this area. If anyone sees the problem, I hope you can help me.

FYI, 0.28 brings experimental support for multi-threading (#7546) and there are some shards like immutable fitting your use-case, but with multiple threads instead of forking. I’d wait a bit rather than fighting with such a low-level code :sweat_smile:

1 Like

Just a note that that PR is about preparing the GC to work in a multithreaded context. Your program will still run in a single thread for now.

I say this to avoid raising everyone’s expectations. Multithreading will come, just not yet.


Answered to your StackOverflow crosspost: https://stackoverflow.com/a/55512196/2199687

Hope I got everything about right, never actually played with this stuff before myself :D


Great explanation and lovely ascii diagrams!

Can’t stop churning on the example code :D https://play.crystal-lang.org/#/r/6nfy

Anyone got an idea to prettify (shared_data.to_unsafe + 1).value.prop = foo? Guess one could have a SharedSlice wrapper struct with some convenience methods…