[ "a" [ 1 1 + ] spawn 100 sleep ] must-fail
[ ] [ 0.1 seconds sleep ] unit-test
+
+! Test thread-local variables
+<promise> "p" set
+
+5 "x" tset
+
+[ 5 ] [ "x" tget ] unit-test
+
+[ ] [ "x" [ 1 + ] tchange ] unit-test
+
+[ 6 ] [ "x" tget ] unit-test
+
+! Are they truly thread-local?
+[ "x" tget "p" get fulfill ] in-thread
+
+[ f ] [ "p" get ?promise ] unit-test
! Thread-local storage
: tnamespace ( -- assoc )
- self variables>> [ H{ } clone dup self (>>variables) ] unless* ;
+ self variables>> ; inline
: tget ( key -- value )
- self variables>> at ;
+ tnamespace at ;
: tset ( value key -- )
tnamespace set-at ;
swap >>name
swap >>quot
\ thread counter >>id
- <box> >>continuation ; inline
+ <box> >>continuation
+ H{ } clone >>variables ; inline
: <thread> ( quot name -- thread )
\ thread new-thread ;