top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to ensure safe access to shared memory?

+2 votes
294 views

Given a shared memory between multiple threads, how will you ensure safe access to memory in different scenarios like reading and writing? If at thr point of wrtitng there are mutiple read requests from threads how pending requests can be managed.

posted Apr 23, 2014 by Atul Mishra

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

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.

answer Apr 23, 2014 by Salil Agrawal
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...