From b169d0efa1503eb521ada37e06cd6a58b9145c83 Mon Sep 17 00:00:00 2001 From: David Xu Date: Mon, 22 Nov 2010 02:42:02 +0000 Subject: [PATCH] Use atomic instruction to set _has_writer, otherwise there is a race causes userland to not wake up a thread sleeping in kernel. MFC after: 3 days --- sys/kern/kern_umtx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index 951fef6cfc03..43570ce5f9be 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -2839,7 +2839,8 @@ do_sem_wait(struct thread *td, struct _usem *sem, struct timespec *timeout) umtxq_insert(uq); umtxq_unlock(&uq->uq_key); - suword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters), 1); + if (fuword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters)) == 0) + casuword32(__DEVOLATILE(uint32_t *, &sem->_has_waiters), 0, 1); count = fuword32(__DEVOLATILE(uint32_t *, &sem->_count)); if (count != 0) {