c++ - How do I take ownership of an abandoned boost::interprocess::interprocess_mutex? -
My scenario: A server and some clients (although not many) can only respond to a customer at a time, at the same time, Therefore, they should be queued for doing this by using a mutex (
boost :: interprocess :: interprocess_mutex
), wrapped in a boost :: interprocess :: scoped_lock
. This is, if a client dies unexpectedly (i.e. the district run) while holding the mute, other clients are in trouble because they are waiting on that mute x. . If this is the case, I say for the customer, waiting 20 seconds and does not get the mutex, it goes anyway from the server further and talks I have considered using time waiting
< P> Any problem with this approach: 1) It does this every time if it is in a loop, then talking constantly on the server, it has to wait for time to finish all the time. 2) If there are three clients, and one of them dies while catching the mute, then wait for the other two 20 seconds and at the same time will talk to the server - exactly what I am trying to avoid.So, how do I find a customer, "Hey there, it has been sacrificed this mutate, taking ownership of it"?
Unfortunately, this boost: not supported by the Interporses API As it is
pthread_mutexattr_setrobust_np, there are a POSIX platform with support for Edit Boost / Interprocess / Sync / POSIX / thread_helpers.hpp and are promoting / Interprocess / Sync / POSIX: There are some ways you can It can however implement /interprocess_mutex.hpp to use strong mutexes, and anybody Shri way to handle EOWNERDEAD return pthread_mutex_lock.
If you are on any other platform, you can use to promote / interproce / sync / simulate / edit the interprocess_mutex.hpp with a generation counter, with the lock flag in the lower bit. Then you can create a recovery protocol that will set a flag in the lock word to indicate a pending recovery, so to check that the same generation lock is still in the word after the timeout is a comparison And swap, and if so, instead of with the value of a closed next generation.
If you are on windows, then another good option would be to use the original mutics object; They will be more efficient than the busy-wait anyway.
Do you want to reconsider the use of share-memory protocols - why not use network protocol instead?