Skip to content

Interoperability with lparallel? [was: SBCL: stmx.lang:*current-thread* seems to never be rebound] #26

Description

@leetwinski

It seems that stmx.lang:*current-thread* special variable is not rebound, breaking interop with lparallel.

Example:

(ql:quickload :stmx)
(ql:quickload :lparallel)

(setf lparallel:*kernel* (lparallel:make-kernel 4))

(lparallel:future
  (stmx:atomic 1))

raises condition:

* Unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "lparallel" RUNNING
                                    {100434F813}>:
  STMX internal error!
  stmx:*current-thread* contains a stale value:
   found #<SB-THREAD:THREAD "main thread" RUNNING {1004AB01F3}>
   expecting #<SB-THREAD:THREAD "lparallel" RUNNING {100434F813}>
Typical cause is:
   new threads were created with implementation-specific functions,
   as for example (sb-thread:make-thread) or (mp:process-run-function),
   that do not apply thread-local bindings stored in
   bordeaux-threads:*default-special-bindings*
Solution:
   use (bordeaux-threads:make-thread) instead.

the following fixes it:

(defmacro lpar-atomic (&body body)
  `(let ((stmx.lang:*current-thread* (lparallel.thread-util:current-thread)))
     (stmx:atomic ,@body)))

(lparallel:future
  (lpar-atomic 1))

though i'm not sure it is a correct approach.
Accorging to sources, i seems that *current-thread* gets bound just once to (bt:current-thread)

SBCL version: 2.1.9
lparallel and stmx are from quicklisp 2021-08-07

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions