1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

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

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;
}