diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h --- a/libc/src/__support/RPC/rpc.h +++ b/libc/src/__support/RPC/rpc.h @@ -248,6 +248,9 @@ if (lock->fetch_or(1, cpp::MemoryOrder::RELAXED)) return cpp::nullopt; + // The mailbox state must be read with the lock held. + atomic_thread_fence(cpp::MemoryOrder::ACQUIRE); + uint32_t in = inbox->load(cpp::MemoryOrder::RELAXED); uint32_t out = outbox->load(cpp::MemoryOrder::RELAXED); @@ -285,6 +288,9 @@ if (lock->fetch_or(1, cpp::MemoryOrder::RELAXED)) return cpp::nullopt; + // The mailbox state must be read with the lock held. + atomic_thread_fence(cpp::MemoryOrder::ACQUIRE); + in = inbox->load(cpp::MemoryOrder::RELAXED); out = outbox->load(cpp::MemoryOrder::RELAXED);