From b23b4d67f154cd7bd2211648dc08d6554117a0da Mon Sep 17 00:00:00 2001 From: Gjon Gojcevic Date: Wed, 7 Oct 2026 20:43:00 -0400 Subject: [PATCH] test(libkernel): wait for the host-blocked worker to take the mutex before relocking In the host-blocked phase of guest_raise_exception, the redirected handler runs as soon as the worker wakes inside pthread_mutex_lock, before it owns hostLock. ExpectDelivery then returns and main relocks hostLock right away. If main wins that race, the worker stays blocked in the previous round's lock_guard, so it never sets started for the next round and main spins forever. The run hangs until the 30 s ctest timeout, with only three RunThread lines in the log. The worker now publishes the round after it acquires the mutex, and main waits for that before relocking. Co-Authored-By: Claude Opus 5.5 --- core/libs/tests/GuestRaiseException.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/libs/tests/GuestRaiseException.cpp b/core/libs/tests/GuestRaiseException.cpp index 4d17541a8..aa715601e 100644 --- a/core/libs/tests/GuestRaiseException.cpp +++ b/core/libs/tests/GuestRaiseException.cpp @@ -73,6 +73,7 @@ static std::mutex hostLock; static constexpr int HostRounds = 20; static std::atomic hostRound{0}; +static std::atomic hostAcquired{0}; static void* APS5_VABI HostBlocked(void* arg) { auto& worker = *static_cast(arg); @@ -81,6 +82,7 @@ static void* APS5_VABI HostBlocked(void* arg) { while (hostRound.load() != round) std::this_thread::yield(); worker.started.store(true); std::lock_guard lock(hostLock); + hostAcquired.store(round + 1); } return nullptr; } @@ -164,6 +166,7 @@ int main() { Require(sceKernelRaiseException(blockedThread, SIGUSR1) == 0); hostLock.unlock(); ExpectDelivery(1 + 2 * Repeats + round, blocked.id); + while (hostAcquired.load() != round + 1) std::this_thread::yield(); hostLock.lock(); blocked.started.store(false); hostRound.store(round + 1);