September 2017
Beginner
402 pages
9h 52m
English
When more then one value is sent to the channel, they in fact become queues. So the first value added will be the first value received from the channel.
As the channels are thread-safe, nobody restricts us about the number of threads, in which we are going to write to a channel or read from it. The following example demonstrates how one channel is shared between a few threads.
This program prints the squares of the numbers from 0 to 10. The numbers are first sent to the channel:
my $channel = Channel.new();$channel.send($_) for 0..10;$channel.close;
The channel is closed after all the number are sent. In the next phase, three threads are created by calling the start function (don't forget that this function creates a thread ...
Read now
Unlock full access