Skip to content

Fix wake on Windows#809

Open
CvvT wants to merge 2 commits intomainfrom
weiteng/fix_wake_on_windows
Open

Fix wake on Windows#809
CvvT wants to merge 2 commits intomainfrom
weiteng/fix_wake_on_windows

Conversation

@CvvT
Copy link
Copy Markdown
Contributor

@CvvT CvvT commented Apr 25, 2026

@sangho2 found out a subtle issue in RwLock with help of GPT-5.5.

Agent implemented a test to reproduce the issue (see test_rwlock_readers_not_starved_after_writer_handoff) and the scenario for the bug is the following:

1. W1 holds the write lock.
2. Reader R blocks, setting `READERS_WAITING`.
3. Writer W2 blocks, setting `WRITERS_WAITING` (and internal `other_writers_waiting`).
4. W1 unlocks → `wake_writer_or_readers` sees both flags, wakes W2, skips readers.
5. W2 acquires the lock **with the `WRITERS_WAITING` bit** (from `other_writers_waiting`).
6. W2 unlocks → `wake_writer_or_readers` sees both flags again, tries to wake a writer.

On Windows wake_one always returns true even though no writer is blocked (because Windows does not tell how may waiters were woken up and our previous implementation just returns the number of waiters requested), so it returns early without waking readers. Readers are stuck forever.

Looking at how std handles Windows, it turns out it always return false (meaning no waiters were woken up). This fix just follows that.

@CvvT CvvT marked this pull request as ready for review April 25, 2026 00:27
@CvvT CvvT changed the title Fix wake on windows Fix wake on Windows Apr 25, 2026
@github-actions
Copy link
Copy Markdown

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

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