quota quotation
namea string

threada thread

Word description
Spawns a new thread. The thread begins executing the given quotation; the name is for debugging purposes. The new thread begins running immediately and the current thread is added to the end of the run queue.

The new thread begins with an empty data stack, an empty retain stack, and an empty catch stack. The name stack is inherited from the parent thread but may be cleared with init-namespaces.

The recommended way to pass data to the new thread is to explicitly construct a quotation containing the data, for example using curry or compose.

A simple thread that adds two numbers:
1 2 [ + . ] 2curry "Addition thread" spawn

A thread that counts to 10:
USING: math.parser threads ; [ 10 <iota> [ number>string write nl yield ] each ] "test" spawn drop 10 [ yield ] times 0 1 2 3 4 5 6 7 8 9


: spawn ( quot name -- thread ) <thread> [ (spawn) ] keep ;