Steel Bank Common Lisp

Windows threading: binding of special vars

Reported by il71 on 2013-04-28
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Undecided
Unassigned

Bug Description

version 1.1.6, x86_64 windows

Well, I know Windows support is still experimental, but still.

Do you guys plan to fix this:

# cat thr.lisp

(require :bordeaux-threads)

(defparameter *x* 0)

(defun print-x ()
  (print *x*))

(let ((*x* 1))
  (bt:make-thread
    #'(lambda ()
        (print-x) ;; 0 -- expected as dynamic binding from parent thread is not inherited
        (let ((*x* 2))
          (print-x))))) ;; 2 on linux, 0 on windows, oops

Stas Boukarev (stassats) wrote :

The problem is not with bindings, but with concurrent printing to the standard output. 0 is printed twice, and 2 is not.

PRINT prints a newline, the thing, and then a space. So the second (print-x) flushes the buffer with 0 is not yet marked as flushed, and it ends up being flushed twice.

Changed in sbcl:
status: New → Invalid
il71 (il71) wrote :

Wow, indeed, this works as expected:

(require :bordeaux-thre

(defparameter *y* 0)
(defparameter *x* 0)

(defun do-x ()
  (incf *y* *x*))

(let ((*x* 1))
  (bt:make-thread
    #'(lambda ()
        (do-x)
        (let ((*x* 2))
          (do-x)))))

(sleep 3)
(print *y*)

Thanks. I bit strange though that 2 was never printed.

il71 (il71) wrote :

On the second thought, in the orig case the output was from the same thread, so it's not concurrent (or is it?).
Looks like a bug to me.

Thanks.

Stas Boukarev (stassats) wrote :

The main thread tries to flush the output after it exists. It's not concurrent printing, but concurrent flushing.

il71 (il71) wrote :

You are right, I should have used synchronization:

(require :bordeaux-threads)

(defparameter *x* 0)

(defun print-x ()
  (print *x*))

(bt:join-thread
  (let ((*x* 1))
    (bt:make-thread
      #'(lambda ()
          (print-x)
          (let ((*x* 2))
            (print-x))))))

My bad.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers