Re: Thread example from evanmiller

2017-09-11 Thread Elizabeth Mattijsen
> On 8 Sep 2017, at 05:16, Norman Gaywood  wrote:
> 
> Several weeks ago there was this post:
> http://www.evanmiller.org/why-im-learning-perl-6.html
> 
> That gave this example of perl6 N:M threads in action:
> 
> use v6.d.PREVIEW;
> 
> my $channel = Channel.new;
> 
> my @ten_tasks = (^10).map: {
> start {
> my $thread = $*THREAD.id;
> await $channel;
> say "HOLY MOLEY SOMEONE STOLE MY THREAD" if $thread != $*THREAD.id;
> }
> }
> 
> $channel.send("Ring ring") for ^10;
> $channel.close;
> 
> await @ten_tasks;
> 
> 
> It demonstrates that perl6 will not tie up a thread in the thread pool just 
> sitting around waiting (I think).
> 
> The example is intended to be condensed without any surplus code.
> So my question is, is the $channel.close required? Leave it out and the code 
> still seems to work. Am I missing some subtle point?

Jonathan tells me the .close is not required:

https://irclog.perlgeek.de/moarvm/2017-09-11#i_15148891


Liz

Thread example from evanmiller

2017-09-07 Thread Norman Gaywood
Several weeks ago there was this post:
http://www.evanmiller.org/why-im-learning-perl-6.html

That gave this example of perl6 N:M threads in action:

use v6.d.PREVIEW;

my $channel = Channel.new;

my @ten_tasks = (^10).map: {
start {
my $thread = $*THREAD.id;
await $channel;
say "HOLY MOLEY SOMEONE STOLE MY THREAD" if $thread != $*THREAD.id;
}
}

$channel.send("Ring ring") for ^10;
$channel.close;

await @ten_tasks;


It demonstrates that perl6 will not tie up a thread in the thread pool just
sitting around waiting (I think).

The example is intended to be condensed without any surplus code.
So my question is, is the $channel.close required? Leave it out and the
code still seems to work. Am I missing some subtle point?

-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html