Skip to content

shared_mutex: Fix races around st_.store()#41

Merged
avdgrinten merged 1 commit intomanagarm:masterfrom
avdgrinten:fix-shared-mutex
Feb 21, 2026
Merged

shared_mutex: Fix races around st_.store()#41
avdgrinten merged 1 commit intomanagarm:masterfrom
avdgrinten:fix-shared-mutex

Conversation

@avdgrinten
Copy link
Member

@avdgrinten avdgrinten commented Feb 20, 2026

The implementation of async::shared_mutex previously did atomic store()s to the state even in situations where the shared lock count can be changed concurrently. This led to a race condition.

  • In lock_shared(), we can simply drop the problematic store() since it only writes back the state that we are currently in anyway.
  • In unlock_shared(), we need a CAS loop to avoid this issue.

The implementation of async::shared_mutex previously did atomic store()s
to the state even in situations where the shared lock count can be changed
concurrently. This led to a race condition.
* In shared_lock(), we can simply drop the problematic store()
  since it only writes back the state that we are currently in anyway.
* In shared_unlock(), we need a CAS loop to avoid this issue.
@avdgrinten avdgrinten requested a review from qookei February 20, 2026 18:33
@avdgrinten avdgrinten merged commit 46e04c7 into managarm:master Feb 21, 2026
1 of 2 checks passed
@avdgrinten avdgrinten deleted the fix-shared-mutex branch February 21, 2026 15:31
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.

2 participants