This is not a Datastructure issue rather IPC/Synchronization issue, by the way it is a famous interview question -
1. Create a mutex and lock it whenever we write something on the shared memory
2. Create a access function which returns false is lock is taken and return true if lock is not there.
Now whenever we want to write something to the shared memory we need to make sure access function returns true and wait for it to return true. If it is true then take a lock and access the memory, once access is over release the lock. Read need not to get impacted because of lock it can directly access shared memory.