How to lock/unlock the shared memory created by mmap?
Hi,all
I create a shared memory with mmap, and share the memory within parent and child process, now I want to lock/unlock the shared memory, how to do this? Thanks. |
Quote:
http://publib.boulder.ibm.com/infoce.../apis/mmap.htm When in doubt, Google it. I taught myself how to program with Google and looking at other people's source code. Good luck! |
It's C.
Maybe I didnt use the right keyword, cannot found anything valuable. |
That depends on what you mean by "lock." Do you mean protect/unprotect, or lock/unlock in physical RAM? The first can be done with mprotect (subject to limitations by the underlying file/device) and the second can be done with mlock. I don't think either will propagate between parents and children, however.
ta0kira PS Or maybe you mean lock for exclusive write access? Look at semget if that's the case. |
process synchronization.
I googled that thread synchronization can use pthread_mutex_lock/unlock, but how process do the lock/unlock? I created a shared memory, and want lock something , and child can read/modify the shared memory until get the lock |
I can't find a reason why to use processes (fork()) and not pthreads when you want to have shared memory....
|
There are quite a few valid reasons to use fork vs. threads (and vice-versa) even with shared memory, but that's an entirely different discussion.
ta0kira |
All times are GMT -5. The time now is 12:16 AM. |