Opened 10 years ago
Last modified 8 years ago
#8094 assigned Feature Requests
hierarchical_mutex for lock hierarchies (to avoid deadlocks)
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | thread |
Version: | Boost 1.53.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
It would be great if boost::thread could be extended with a "hierarchical" mutex to facilitate lock hierarchies. Lock hierarchies is a construct that associates mutexes with software layer numbers, and enforces the application to only lock "downwards" in the software hierarchy [1]. This effectively translates potential deadlocks into deterministic run-time failures that be detected during testing.
An example draft implementation is attached. The attachment also includes a BOOST_THREAD_LOCAL work-around for missing "thread_local" support that should probably be moved to more neutral ground.
[1] http://www.drdobbs.com/parallel/use-lock-hierarchies-to-avoid-deadlock/204801163
Attachments (2)
Change History (7)
by , 10 years ago
Attachment: | hierarchical_mutex.hpp added |
---|
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Version: | Boost 1.52.0 → Boost 1.53.0 |
comment:2 by , 8 years ago
Hi Frederick,
what kind of license is you code? Am I allowed to use it as i like? Is it the same as thread's (http://www.boost.org/LICENSE_1_0.txt)
Cheers!
Jan
comment:4 by , 8 years ago
Do you mind to provide some documentation and tests and update your code with the Boost license?
comment:5 by , 8 years ago
I've now uploaded a 7-zip archive with an updated hierarchical_mutex implementation. All files are tagged with Boost license information. The archive also contains a tiny test suite, as well as a semi-portable "thread_local" emulation.
Feel free to do what ever you want with the implementation. I hope that Boost could consider adopting this pattern in one way or another, since it makes debugging and avoiding deadlocks much easier.
I agree, and I had already on my to do list. However, much more work is needed to move it to Boost:
if you can help on any of these task there are more chances the feature is included.
BTW, alternatively you can provide this hierarchical mutex class as a separated library if you prefer.