Thread-local state and variables
Factor handbook » The language » Co-operative threads

Prev:Yielding and suspending threads
Next:Thread implementation


Threads form a class of objects:
thread


The current thread:
self ( -- thread )


Thread-local variables:
tnamespace ( -- assoc )

tget ( key -- value )

tset ( value key -- )

tchange ( ..a key quot: ( ..a value -- ..b newvalue ) -- ..b )


Each thread has its own independent set of thread-local variables and newly-spawned threads begin with an empty set.

Global hashtable of all threads, keyed by id:
threads ( -- assoc )


Threads have an identity independent of continuations. If a continuation is reified in one thread and then reflected in another thread, the code running in that continuation will observe a change in the value output by self.