Then, I try to write some data to the shared memory segment using both the processes, so for me to prevent any race condition (data corruption), either these operations must be atomic, or I should be able to lock / unlock shared memory segment, which I cannot at the moment.
I earlier posted a solution to this problem, which received positive response, but there weren’t many responses to it, despite the fact this problem makes shared_memory practically unusable if there are simultaneous writes.
So, the purpose of this post is to have discussion about the solution of the same.
1. Support for shared semaphores across unrelated processes to lock/unlock shared memory segment.
2. Let the first bit in the shared memory segment be the synchronisation bit used for locking/unlocking.
--> A process can only lock the shared memory segment if this bit is unset, and will set this bit after acquiring lock, and similarly unset this bit after unlocking. Although set/unset operations must be atomic. Therefore, the following tools can be used:
Any other ideas/solutions are very welcome.