Skip to content

fix(hle): release mutexes when their owner thread exits - #90

Merged
github-actions[bot] merged 1 commit into
masterfrom
fix/mutex-owner-exit-8
Nov 6, 2026
Merged

github-actions[bot] merged 1 commit into
masterfrom
fix/mutex-owner-exit-8

Conversation

@endercodezz

Copy link
Copy Markdown
Owner

What changed

exit_current_thread now frees the mutexes of the ending thread and hands each to its next waiter. Before, waiters on such a mutex never woke.

Issue #8 named lwmutexes too, but the PSP behaves differently there, so they stay as they are:

pspautotests lock.expected Here
mutex "Woke up after other thread exited." released on exit
lwmutex "Did not wake on thread exit: OK" stays locked, pinned by a test

An lwmutex's state is in the guest's workarea, not in the kernel. sceKernelTerminateThread is not implemented and delete_thread only takes ended threads, so exit is the only path.

Verification

  • test_threadman_sync: 3 new cases, 5 failed checks before the fix, 0 after.
  • CTest 32/32.
  • new_game.txt to vblank 9000 before and after: identical event dumps, SHA-256 0364bf64f29b9434.... That route never ends a thread holding a mutex.

Not verified

  • [INFERRED] A waiter gets the mutex with result 0, as PPSSPP does. The pspautotests case locks after the owner has exited.
  • [UNVERIFIED] Routes other than new_game.txt.

Closes #8

A mutex stayed locked after its owner ended, so its waiters never woke.
The kernel frees it on the PSP and hands it to the next waiter. An lwmutex
stays locked there, because its state is in the guest's workarea, so only
mutexes change, and a test pins the lwmutex behaviour.

Verified: pspautotests threads/mutex and threads/lwmutex lock.expected;
test_threadman_sync 5 failures before, 0 after; CTest 32/32; new_game.txt
to vblank 9000 gives identical events, SHA-256 0364bf64f29b9434.
@github-actions
github-actions Bot enabled auto-merge November 6, 2026 16:43
@github-actions
github-actions Bot merged commit ce587d4 into master Nov 6, 2026
9 checks passed
@endercodezz
endercodezz deleted the fix/mutex-owner-exit-8 branch November 6, 2026 19:42
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.

ThreadMan: mutexes and lwmutexes are not released when their owner thread exits

1 participant