develooper Front page | perl.perl6.users | Postings from September 2017

Re: Thread example from evanmiller

Thread Previous
From:
Elizabeth Mattijsen
Date:
September 11, 2017 21:49
Subject:
Re: Thread example from evanmiller
Message ID:
66DD3820-0B8F-415A-BFAE-CCEB1D9F176C@dijkmat.nl
> On 8 Sep 2017, at 05:16, Norman Gaywood <ngaywood@une.edu.au> 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 Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About