Skip to content
Browse files

Do not use RETURN-FROM in MAKE-THREAD

Fix for lp#1058799, regression in 1.0.56.55-f0da2f6.
  • Loading branch information...
1 parent 8073844 commit 991c149c68b5e60a3824fa2af09403d49e0af341 @lichtblau lichtblau committed Sep 30, 2012
Showing with 9 additions and 12 deletions.
  1. +2 −0 NEWS
  2. +7 −12 src/code/target-thread.lisp
View
2 NEWS
@@ -26,6 +26,8 @@ changes relative to sbcl-1.0.58:
into a DEFCAS defined place was used as the place.
* bug fix: FIND and POSITION signaled a type-error when non-bits where looked
for from bit-vectors.
+ * bug fix: a race condition around thread creation could (in SBCL 1.0.57)
+ lead to internal errors or crashes (lp#1058799).
* documentation: a section on random number generation has been added to the
manual. (lp#656839)
View
19 src/code/target-thread.lisp
@@ -1368,10 +1368,9 @@ See also: RETURN-FROM-THREAD, ABORT-THREAD."
"Argument passed to ~S, ~S, is an improper list."
'make-thread arguments)
#!+sb-thread
- (tagbody
+ (let ((thread (%make-thread :name name :%ephemeral-p ephemeral)))
(with-mutex (*make-thread-lock*)
- (let* ((thread (%make-thread :name name :%ephemeral-p ephemeral))
- (setup-sem (make-semaphore :name "Thread setup semaphore"))
+ (let* ((setup-sem (make-semaphore :name "Thread setup semaphore"))
(real-function (coerce function 'function))
(arguments (if (listp arguments)
arguments
@@ -1461,15 +1460,11 @@ See also: RETURN-FROM-THREAD, ABORT-THREAD."
;; thread.
(without-interrupts
(with-pinned-objects (initial-function)
- (let ((os-thread
- (%create-thread
- (get-lisp-obj-address initial-function))))
- (when (zerop os-thread)
- (go :cant-spawn))
- (wait-on-semaphore setup-sem)
- (return-from make-thread thread))))))
- :cant-spawn
- (error "Could not create a new thread.")))
+ (if (zerop
+ (%create-thread (get-lisp-obj-address initial-function)))
+ (setf thread nil)
+ (wait-on-semaphore setup-sem))))))
+ (or thread (error "Could not create a new thread."))))
(defun join-thread (thread &key (default nil defaultp) timeout)
#!+sb-doc

0 comments on commit 991c149

Please sign in to comment.
Something went wrong with that request. Please try again.