Skip to content

Fix/windows condvar stale wake guard#4123

Open
w1naenator wants to merge 4 commits intoshadps4-emu:mainfrom
w1naenator:fix/windows-condvar-stale-wake-guard
Open

Fix/windows condvar stale wake guard#4123
w1naenator wants to merge 4 commits intoshadps4-emu:mainfrom
w1naenator:fix/windows-condvar-stale-wake-guard

Conversation

@w1naenator
Copy link
Copy Markdown
Contributor

  • Added a non-alertable zero-time semaphore acquire path for wake draining on Windows.
  • Added wait-generation tracking per thread and generation-aware deferred wake entries.
  • Changed wake delivery so a wake is released only if waiter generation still matches (prevents stale wake release).
  • Added stale carryover filtering in wait loop for the N→N+1 wake-token race window.

w1naenator and others added 2 commits March 13, 2026 03:20
- Added a non-alertable zero-time semaphore acquire path for wake draining on Windows.
- Added wait-generation tracking per thread and generation-aware deferred wake entries.
- Changed wake delivery so a wake is released only if waiter generation still matches (prevents stale wake release).
- Added stale carryover filtering in wait loop for the N→N+1 wake-token race window.

What this fixes:

- Prevents obsolete wake tokens from corrupting condvar state on Windows.
- Removes the need for workaround behavior that masked unexpected wakes.
- Restores stable wait/wake behavior while staying close to original main style.
@w1naenator
Copy link
Copy Markdown
Contributor Author

This fixes a random crash in the Ratchet and Clank title on the Windows emulator build.

@StevenMiller123
Copy link
Copy Markdown
Collaborator

For the record, the condvar issues are present cross platform, it's not just a Windows bug. I'll do some tests when I can to check the condvar issues on Windows and Linux.

@StevenMiller123
Copy link
Copy Markdown
Collaborator

I've yet to run into any condvar unreachables on Windows with this PR. I do still hit them on Linux though.
Perhaps it would be beneficial to allow some of this "Windows" code to run on Linux?

@w1naenator
Copy link
Copy Markdown
Contributor Author

I've yet to run into any condvar unreachables on Windows with this PR. I do still hit them on Linux though. Perhaps it would be beneficial to allow some of this "Windows" code to run on Linux?

On my Ubuntu machine (with different hardware than my Windows system), Ratchet and Clank runs stable and I have not encountered the condvar crash there.

If you have a list of titles that still trigger the condvar issue on Linux, please share them. I can try reproducing the problem on my system and report back.

@w1naenator
Copy link
Copy Markdown
Contributor Author

I’m surprised that the emulator runs much more stably on an NVIDIA Quadro T2000 Max-Q with an Intel Core i9-10885H than on a NVIDIA GeForce RTX 3070 Ti Laptop GPU with a 12th Gen Intel Core i9-12900H.

@w1naenator
Copy link
Copy Markdown
Contributor Author

w1naenator commented Mar 13, 2026

Quadro
Screenshot 2026-03-13 112925

RTX
Screenshot 2026-03-13 133228

@StevenMiller123
Copy link
Copy Markdown
Collaborator

The affected games between platforms are identical. My go-tos for testing were always Uncharted: The Nathan Drake Collection and Marvel's Spider-Man.
It's worth noting that this crash is far less frequent on stronger CPUs.

@tochnonechelovek
Copy link
Copy Markdown

No regressions in my titles.

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.

3 participants