Seems that Boost's shared_mutex is non recursive.. Is there anyway around this? (without re implementing the whole stuff)
Seems that Boost's shared_mutex is non recursive.. Is there anyway around this? (without re implementing the whole stuff)
have a look at this thread and this excellent explanation why shared_mutex is bad idea in general. so if you don't agree that recursive_mutex is bad idea too, just use it without any shariness because it cannot give you any performance boost. you'll receive even a bit cleaner code w/o any major changes.
I tried to use shared_mutex in my project to lock highly contested map when many threads often read data and rarely modify it. received a bit worse performance results
I've been down this road personally before. The simple answer is no, there is no shared_recursive_mutex.
I don't really agree with what others will tell you about how recursive mutexes are generally a bad idea, it certainly can save some time and prevent some errors. However, if you don't want to implement your own shared_recursive_mutex, you'll have to stick with non-recursive mutexes. It's not so bad.
boost::recursive mutex is exclusive. I think you will need to extend shared_mutex. You can keep current thread ID in a set and check if it exist in the set in function providing lock.