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

Thread example from evanmiller

Thread Next
From:
Norman Gaywood
Date:
September 8, 2017 03:17
Subject:
Thread example from evanmiller
Message ID:
CAHJ-_U6itP_YGHgOsxZDfbkjCtk2XZ8-1ifeYeaRhG-7_o38+Q@mail.gmail.com
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

ngaywood@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

Thread Next


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