Linux inter-process reentrant semaphore?

You can just use a shared (interprocess) recursive pthread_mutex_t Create a normal pthread_mutex (stored in shared memory) and set its attributes using pthread_mutexattr_settype with the PTHREAD_MUTEX_RECURSIVE flag, and then call pthread_mutexattr_setpshared with the PTHREAD_MUTEX_SHARED flag.

You can just use a shared (interprocess), recursive pthread_mutex_t. Create a normal pthread_mutex (stored in shared memory) and set its attributes using pthread_mutexattr_settype with the PTHREAD_MUTEX_RECURSIVE flag, and then call pthread_mutexattr_setpshared with the PTHREAD_MUTEX_SHARED flag. That will give you a reentrant, interprocess lock.

Storing the mutex in the shared memory is not ideal. But if I can't find something better I guess I will have to go with this. – Adal Nov 17 '09 at 14:15 You have no choice.

The mutex has to be stored in shared memory if you want it to be interprocess – Charles Salvia Nov 17 '09 at 14:15 boost::interprocess::named_recursive_mutex seems to do just this. I will give you the answer points, since the other answer pointing to boost::interprocess::named_mutex has disappeared (even if it was not the recursive one). – Adal Nov 17 '09 at 15:32 1 Charles is right.

Boost::interprocess::named_recursive_mutex just hides the fact that it uses shared memory. See "detail::managed_open_or_create_impl m_shmem;" – Paul Du Bois Nov 17 '09 at 0:46.

You could try building your own out of futexes. See usersem. C in this tarball.

I also need for this port something similar to a Windows CRITICAL_SECTION, and futex seems to be just that. The problem is that it seems that the futex does not have yet a Lock/Unlock simple API to use, and from what I've seen it's not trivial to use (lots of traps you can fall into). And since my Linux fu is not that great yet, I'm sticking to simpler primitives for now.

– Adal Nov 17 '09 at 13:40.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions