Inherit FP modes for new threads on Windows.
authorStas Boukarev <stassats@gmail.com>
Sat, 16 Nov 2013 10:23:08 +0000 (14:23 +0400)
committerStas Boukarev <stassats@gmail.com>
Sat, 16 Nov 2013 10:23:08 +0000 (14:23 +0400)
Newly created threads have all the traps cleared, while on other
platforms they are inherited from the parent thread.

src/code/target-thread.lisp
tests/threads.impure.lisp

index d037f45..402fe68 100644 (file)
@@ -1453,8 +1453,15 @@ See also: RETURN-FROM-THREAD, ABORT-THREAD."
            (arguments     (if (listp arguments)
                               arguments
                               (list arguments)))
+           #!+win32
+           (fp-modes (dpb 0 sb!vm::float-sticky-bits ;; clear accrued bits
+                          (sb!vm:floating-point-modes)))
            (initial-function
              (named-lambda initial-thread-function ()
+               ;; Win32 doesn't inherit parent thread's FP modes,
+               ;; while it seems to happen everywhere else
+               #!+win32
+               (setf (sb!vm:floating-point-modes) fp-modes)
                ;; As it is, this lambda must not cons until we are
                ;; ready to run GC. Be very careful.
                (initial-thread-function-trampoline
index 5da2c1b..788862b 100644 (file)
    (sb-thread:make-thread
     (lambda ()
       (alien-funcall (extern-alien "alloca_test" (function void)))))))
+
+(with-test (:name :fp-mode-inheritance-threads)
+  (flet ((test ()
+           (let ((thread-fp-mode)
+                 (fp-mode (dpb 0 sb-vm::float-sticky-bits (sb-vm:floating-point-modes))))
+             (sb-thread:join-thread
+              (sb-thread:make-thread
+               (lambda ()
+                 (setf thread-fp-mode
+                       (dpb 0 sb-vm::float-sticky-bits (sb-vm:floating-point-modes))))))
+             (assert (= fp-mode thread-fp-mode)))))
+    (test)
+    (sb-int:with-float-traps-masked (:divide-by-zero)
+      (test))
+    (setf (sb-vm:floating-point-modes)
+          (dpb sb-vm:float-divide-by-zero-trap-bit
+               sb-vm::float-traps-byte
+               (sb-vm:floating-point-modes)))
+    (test)))