Skip to content

fix(posix): make mutex robust, handle EOWNERDEAD - #1573

Open
philphauler wants to merge 1 commit into
nasa:devfrom
philphauler:fix-2433-robust-mutex
Open

fix(posix): make mutex robust, handle EOWNERDEAD#1573
philphauler wants to merge 1 commit into
nasa:devfrom
philphauler:fix-2433-robust-mutex

Conversation

@philphauler

Copy link
Copy Markdown

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.

@philphauler
philphauler force-pushed the fix-2433-robust-mutex branch from a9c48a9 to 7a001ad Compare August 29, 2026 14:42
@joelsherrill

Copy link
Copy Markdown

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. :)

Comment thread src/os/posix/src/os-impl-mutex.c Fixed
@dzbaker

dzbaker commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

@philphauler Thank you for your contribution. Please resolve the workflow failures.

@philphauler
philphauler force-pushed the fix-2433-robust-mutex branch from 7a001ad to 85faa90 Compare August 31, 2026 15:23
Set PTHREAD_MUTEX_ROBUST and recover via pthread_mutex_consistent on
EOWNERDEAD so cancellation during shutdown does not deadlock penders.

Fixes #2433
@philphauler
philphauler force-pushed the fix-2433-robust-mutex branch from 85faa90 to 6468b62 Compare August 31, 2026 15:47
** 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 sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants