-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iox #325 deadlock in shared mem mutex #330
Iox #325 deadlock in shared mem mutex #330
Conversation
…case application fails to unlock mutex and terminate Signed-off-by: Sumedha Maharudrayya Mathad (RBEI/ESU4) <[email protected]>
Signed-off-by: Hintz Martin (CC-AD/ESW1) <[email protected]>
Signed-off-by: Hintz Martin (CC-AD/ESW1) <[email protected]>
Signed-off-by: Hintz Martin (CC-AD/ESW1) <[email protected]>
6dba6b2
to
ecac6fd
Compare
Robust mutex is not supported on Win/Mac. We need to find a solution! |
Windows and Mac builds are broken :-( IMHO best solution would be to add empty wrappers for e.g. |
This will prevent a deadlock and makes the mutex consistent again. What's your feeling on this @marthtz @sculpordwarf ? |
Windows: WAIT_ABANDONED |
You're right @budrus, we're getting into difficult terrain here. All shared data protected by an invalid mutex should be treated as corrupted. Off the top of my head we could do two things when an invalid mutex has been detected. We could either re-init these data blocks or we throw an error (and may shutdown gracefully). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix Mac OS behavior so that is consistent with linux (if possible)
- Find robust mutex solution for windows (if possible)
- Add additional unit tests for mutex
/// @param[in] robust If robust is set ON, a process or thread can exit while having the lock without causing an | ||
/// invalid mutex. In the next lock call to this mutex the system recognizes the mutex is locked by a dead process | ||
/// or thread and allows the mutex to be restored. | ||
mutex(const Recursive recursive, const Robust robust); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add noexcept
@@ -50,6 +50,16 @@ mutex::mutex(bool f_isRecursive) | |||
&attr, | |||
PTHREAD_PRIO_NONE) | |||
.hasErrors(); | |||
if (robust == Robust::ON) | |||
{ | |||
isInitialized &= !cxx::makeSmartC(pthread_mutexattr_setrobust, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this call is not supported for Mac OS and therefore has to be reimplemented and I am not aware if Windows is supporting robust mutexes?!
But maybe you can follow up this link: https://stackoverflow.com/questions/24946886/is-there-pthread-mutex-robust-equivalent-in-mac-os-x or contact me and we can work together on a solution.
@@ -47,7 +48,7 @@ class Mutex_test : public Test | |||
} | |||
} | |||
|
|||
iox::posix::mutex sut{false}; | |||
mutex_t sut{mutex_t::Recursive::OFF, mutex_t::Robust::OFF}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test cases for recursive and robust mutexes are missing.
Like:
- normal creation and usage should work for recursive, robust and recursive and robust mutex
- multiple locks should not lead to deadlock in a recursive mutex in a single thread
- multiple locks should cause a deadlock in a recursive mutex from different threads (start multiple threads, let the first thread deadlock and then unlock the mutex in the thread it was locked before)
- robust mutex cleanup should work ... here we maybe have to think how we can test it. @marthtz do you have an idea?
Isn't it the case that with the introduction of the building blocks / new API the number of mutexes is reduced?! So, maybe the robust approach is a bit over the top? |
So we would have to provide this information and not silently make the mutex consistent again. |
They are reduced but not completely eliminated |
My proposal after some discussion with @sculpordwarf :
|
@marthtz is this PR dead? Can we remove it? |
@marthtz I assume that this PR is dead and remove it. If I am mistaken just reopen it. |
Introduce a robust, recursive mutex.
If recursive is enabled, the same thread, which has already locked the mutex, can lock the mutex again without getting blocked.
If robust is enabled, a process or thread can exit while having the lock without causing an invalid mutex. In the next lock call to this mutex the system recognizes the mutex is locked by a dead process or thread and allows the mutex to be restored.