diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-06-02 06:23:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-02 18:09:32 +0200 |
commit | 90f4c9e44c10bd6035050daefaa2aa6fa3e683e1 (patch) | |
tree | 7151512748be2dc1858a7b9fa91cc9632fe51694 | |
parent | 5ca1d4289b035918ed989ce4159c39996cddd725 (diff) | |
download | serenity-90f4c9e44c10bd6035050daefaa2aa6fa3e683e1.zip |
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.
-rw-r--r-- | Userland/Libraries/LibC/pthread_integration.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibC/pthread_integration.cpp b/Userland/Libraries/LibC/pthread_integration.cpp index 9b7d3db35f..f0ef135b25 100644 --- a/Userland/Libraries/LibC/pthread_integration.cpp +++ b/Userland/Libraries/LibC/pthread_integration.cpp @@ -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; } |