LibC: Fix race condition in pthread_mutex_unlock()

This ensures the store to mutex->lock doesn't get re-ordered before
the store to mutex->owner which could otherwise result in a locked
owner-less mutex if another thread tries to acquire the lock at
the same time.
This commit is contained in:
Gunnar Beutner 2021-06-02 06:23:31 +02:00 committed by Andreas Kling
parent 5ca1d4289b
commit 90f4c9e44c
Notes: sideshowbarker 2024-07-18 17:00:13 +09:00

View file

@ -119,7 +119,7 @@ int __pthread_mutex_unlock(pthread_mutex_t* mutex)
return 0;
}
mutex->owner = 0;
mutex->lock = 0;
AK::atomic_store(&mutex->lock, 0u, AK::memory_order_release);
return 0;
}