Sending and receiving messages
Message-passing concurrency

Next:Synchronous sends

Each thread has an associated mailbox. Other threads can place items on this queue by sending the thread a message. A thread can check its mailbox for messages, blocking if none are pending, and thread them as they are queued.

The messages that are sent from thread to thread are any Factor value. Factor tuples are ideal for this sort of thing as you can send a tuple to a thread and the generic word dispatch mechanism can be used to perform actions depending on what the type of the tuple is.

The spawn word pushes the newly-created thread on the calling thread's stack; this thread object can then be sent messages:
send ( message thread -- )

A thread can get a message from its queue:
receive ( -- message )

receive-timeout ( timeout -- message )

receive-if ( pred -- message )

receive-if-timeout ( timeout pred -- message )

See also