-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interoperability with lparallel? [was: SBCL: stmx.lang:*current-thread* seems to never be rebound] #26
Comments
Is it even a viable idea to use stmx with fixed-size thread pool, as those of lparallel? |
Hi @leetwinski, There is a requirement, though: each thread that will access stmx variables, functions or macros must first set some thread-local bindings (in Lisp parlance, locally bind some special variables). STMX stores the list of such bindings in the variable If you create threads with some other mechanism, you need to set such local bindings yourself, for example by defining the following macro: (defmacro with-initial-bindings (&body body)
`(let ,(loop for pair in bordeaux-threads:*default-special-bindings*
for name = (first pair)
for bind = (rest pair)
collect `(,name ,bind))
,@body)) and wrapping all code executed by a new thread inside it, as for example: (with-initial-bindings
(call-lparallel-thread-main-loop)) ; hypothetical function The list of initial bindings depends on STMX version, and it currently includes local bindings for at least the following special variables: stmx::*tlog-pool*
stmx::*hw-tlog-write-version*
stmx::*hide-tvars*
stmx::*record-to-tlogs*
stmx::*tlog*
stmx::*tvar-id*
stmx::*lv*
stmx.lang::*cons-pool*
stmx.lang:*current-thread* as you may check by examining the value of The macro P.S. I recommend calling |
[UPDATE]
[FURTHER UPDATE]
A conversion function is not difficult, please reply here if you need help to implement it. |
Hi @cosmos72 Anyways this one is very helpful! And thanks for |
Good :) In detail:The bindings argument passed to This is not what STMX expects: the alist So the only immediate solution is to use the macro In the long term, it may be better to ask lparallel authors to improve compatibility with bordeaux-threads,
|
@cosmos72 thanks again! I decided to make this little patch in lparallel repo. It seems to fix my problem. So i would probably use the fork, untill (unless) they merge it. Once again: thank you for your guidance! |
So you found that lparallel creates threads with Yes, that definitely was the problem - and your fix looks correct to me 👍 |
It seems that
stmx.lang:*current-thread*
special variable is not rebound, breaking interop with lparallel.Example:
raises condition:
the following fixes it:
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)
The text was updated successfully, but these errors were encountered: