Skip to content

Restored inherited priority when a mutex waiter stops waiting - #807

Open
howjmay wants to merge 1 commit into
eclipse-threadx:masterfrom
howjmay:fix/mutex-inherit-wait-exit
Open

howjmay wants to merge 1 commit into
eclipse-threadx:masterfrom
howjmay:fix/mutex-inherit-wait-exit

Conversation

@howjmay

@howjmay howjmay commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

When a thread blocks on a TX_INHERIT mutex, the owner is raised to the waiter's priority. If the waiter then leaves the suspension list without the mutex -- on a wait timeout, tx_thread_wait_abort or tx_thread_terminate -- _tx_mutex_cleanup unlinked it but left tx_mutex_highest_priority_waiting and the owner's priority as they were. Only tx_mutex_put recomputed them, so the owner kept the departed waiter's priority for as long as it held the mutex, and every thread between the two priorities was starved.

_tx_mutex_cleanup now calls a new internal function, _tx_mutex_inherit_priority_update, after unlinking a waiter from an inheriting mutex. It recomputes the mutex's highest waiting priority from its suspension list, recomputes the owner's inherited priority across every mutex the owner holds, and changes the owner's priority if it differs from the higher of that and the owner's own. It follows the preemption-disable pattern _tx_mutex_put uses around _tx_mutex_prioritize and _tx_mutex_priority_change. Applied to common and common_smp, where both files are identical.

threadx_mutex_inherit_wait_exit_test covers a single waiter leaving by each of the three routes, three waiters leaving one by one, and an owner still inheriting from a second mutex. Added to both suites. Without the fix it fails with ERROR #15 in both; with it, all 114 tests of the single-core default_build_coverage configuration pass, the mutex tests pass in the SMP default_build_coverage configuration, and the changed sources build cleanly under -Wall -Wextra -Werror with TX_NOT_INTERRUPTABLE, TX_MISRA_ENABLE, TX_DISABLE_PREEMPTION_THRESHOLD and event trace.

PR checklist

  • Updated function header with a short description and version number
  • Added test case for bug fix or new feature
  • Validated on real hardware

When a thread blocks on a TX_INHERIT mutex, the owner is raised to the waiter's
priority. If the waiter then leaves the suspension list without the mutex -- on a wait
timeout, tx_thread_wait_abort or tx_thread_terminate -- _tx_mutex_cleanup unlinked it
but left tx_mutex_highest_priority_waiting and the owner's priority as they were. Only
tx_mutex_put recomputed them, so the owner kept the departed waiter's priority for as
long as it held the mutex, and every thread between the two priorities was starved.

_tx_mutex_cleanup now calls a new internal function, _tx_mutex_inherit_priority_update,
after unlinking a waiter from an inheriting mutex. It recomputes the mutex's highest
waiting priority from its suspension list, recomputes the owner's inherited priority
across every mutex the owner holds, and changes the owner's priority if it differs from
the higher of that and the owner's own. It follows the preemption-disable pattern
_tx_mutex_put uses around _tx_mutex_prioritize and _tx_mutex_priority_change. Applied to
common and common_smp, where both files are identical.

threadx_mutex_inherit_wait_exit_test removes a single waiter by each of the three
routes, then aborts four waiters spread over two mutexes in turn. Added to both suites.
Without the fix it fails with ERROR eclipse-threadx#12 in both; with it, the mutex tests pass in both
suites' default_build_coverage configuration, and the changed sources build cleanly
under -Wall -Wextra -Werror with TX_NOT_INTERRUPTABLE, TX_MISRA_ENABLE,
TX_DISABLE_PREEMPTION_THRESHOLD and event trace.
@howjmay
howjmay force-pushed the fix/mutex-inherit-wait-exit branch from 66bce86 to d2db0b3 Compare October 13, 2026 18:54

This branch has not been deployed

No deployments
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.

1 participant