Routines, smalltalk coroutines

Routines are smalltalk coroutines? Is there a way to communicate between Routines, via channels or something? Is there any background information about this somewhere?

Routines are not parallel, they are concurrent, and the scheduler uses only one CPU thread. So, they can share data, with no problems. Check the help file for Rational Quark, there is an example of that.

1 Like

If you want a Channel, here is one that I use sometimes. I haven’t tested this that thoroughly so there could be some bugs.

It lets you, push and pop from different threads.

Popping lets you set a timeout, the number of items you wish to pop, an option whether this should only pop exactly that number, up to that number, or more than it.

Push lets you close the channel.

There is no documentation yet, and I will eventually turn in into a quark.

Usage for an channel that never closes

~ch = Channel();

fork { loop {
	5.0.rand.wait;
	~ch.push(5.0.rand.debug(\inserting), close: false);
}};

fork { loop {
	~ch.pop(count: 1, timeout:20).debug(\got)
}};

for a channel that closes

~ch = Channel();
~ch.push(5.0.rand.debug(\inserting), close: true);
fork { ~ch.doUntilClosed({|value| value.debug(\got) }) }

To install:

Quarks.install("https://github.com/JordanHendersonMusic/BarrierAndChannel")
1 Like