Object exchange points


The concurrency.exchangers vocabulary implements object exchange points, which are rendezvous points where two threads can exchange objects.
exchanger

<exchanger> ( -- exchanger )

exchange ( obj exchanger -- newobj )


One use-case is two threads, where one thread reads data into a buffer and another thread processes the data. The reader thread can begin by reading the data, then passing the buffer through an exchanger, then recursing. The processing thread can begin by creating an empty buffer, and exchanging it through the exchanger. It then processes the result and recurses.

The vocabulary was modelled after a similar feature in Java's java.util.concurrent library.