From 90f4c9e44c10bd6035050daefaa2aa6fa3e683e1 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 2 Jun 2021 06:23:31 +0200 Subject: 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. --- Userland/Libraries/LibC/pthread_integration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } -- cgit v1.2.3