I want to use a mutex which will be used to synchronize access to some variables residing in the memory shared b/w two different processes. How can I achieve that. Code sample to perform that will be very appreciated.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a POSIX semaphore initialized to(See below) Use1instead.sem_initfor unnamed semaphores orsem_openfor named ones.Many years after initially posting this answer, it has to be updated.
Mutexes should actually be used instead of semaphores. R and kuga’s comments (copied verbatim below) explain why. In particular I find kuga’s mention that mutexes can only be
posted by their locking thread most compelling.R
kuga