From d4269db7d3211f7fb00003f9c36eff109deb8caa Mon Sep 17 00:00:00 2001 From: Nikodemus Siivola Date: Mon, 29 Mar 2010 08:05:11 +0000 Subject: [PATCH] 1.0.37.14: fix the other half of the WAIT-ON-SEMAPHORE buglet * ATOMIC-DECF doesn't do any good if the other write isn't atomic as well: even though we are always holding the lock while incrementing the waitcount, the possibly unlocked but atomic decrement means the increment needs to be atomic too. --- src/code/target-thread.lisp | 6 +++++- version.lisp-expr | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/code/target-thread.lisp b/src/code/target-thread.lisp index 51e4c42..72d0af4 100644 --- a/src/code/target-thread.lisp +++ b/src/code/target-thread.lisp @@ -678,7 +678,11 @@ negative. Else blocks until the semaphore can be decremented." (setf (semaphore-%count semaphore) (1- count)) (unwind-protect (progn - (incf (semaphore-waitcount semaphore)) + ;; Need to use ATOMIC-INCF despite the lock, because on our + ;; way out from here we might not be locked anymore -- so + ;; another thread might be tweaking this in parallel using + ;; ATOMIC-DECF. + (atomic-incf (semaphore-waitcount semaphore)) (loop until (plusp (setf count (semaphore-%count semaphore))) do (condition-wait (semaphore-queue semaphore) (semaphore-mutex semaphore))) diff --git a/version.lisp-expr b/version.lisp-expr index 12c3089..5093ca6 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.37.13" +"1.0.37.14" -- 1.7.10.4