fix(posix): make mutex robust, handle EOWNERDEAD - #1573
Conversation
a9c48a9 to
7a001ad
Compare
|
The robust APIs are not supported by RTEMS or required by the FACE Technical Standard. This code needs to account for it not being universally available. Obviously, someone's free to submit the code required to support this in RTEMS. :) |
|
@philphauler Thank you for your contribution. Please resolve the workflow failures. |
7a001ad to
85faa90
Compare
Set PTHREAD_MUTEX_ROBUST and recover via pthread_mutex_consistent on EOWNERDEAD so cancellation during shutdown does not deadlock penders. Fixes #2433
85faa90 to
6468b62
Compare
| ** tasks that pend on it. See nasa/cFE#2433. | ||
| ** Note: Robust mutex not supported on RTEMS/FACE, skip if unavailable. | ||
| */ | ||
| #ifdef PTHREAD_MUTEX_ROBUST |
| ** Lock the mutex | ||
| */ | ||
| status = pthread_mutex_lock(&(impl->id)); | ||
| #ifdef EOWNERDEAD |
| ** the lock can be safely used. See nasa/cFE#2433. | ||
| ** Note: Robust not supported on RTEMS/FACE, guard EOWNERDEAD. | ||
| */ | ||
| status = pthread_mutex_consistent(&(impl->id)); |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
I think the feature guard is ineffective on glibc/Linux: PTHREAD_MUTEX_ROBUST is an enum constant, not a preprocessor macro, so #ifdef PTHREAD_MUTEX_ROBUST evaluates false and the mutex never becomes robust. That leaves the original deadlock behavior intact on Linux. Could this be gated by an actual platform/feature-test macro (or CMake capability check) and covered by a Linux test that kills the owner and observes EOWNERDEAD?
Fixes #2433
Set PTHREAD_MUTEX_ROBUST and recover via pthread_mutex_consistent on EOWNERDEAD. Prevents deadlock when owning thread cancelled during shutdown.
AI Used: y - reviewed.