Skip to Content
Perl 6 Deep Dive
book

Perl 6 Deep Dive

by Andrew Shitov
September 2017
Beginner
402 pages
9h 52m
English
Packt Publishing
Content preview from Perl 6 Deep Dive

The id and name methods

In the Starting a new thread section, we have already seen a few examples of how identifiers are assigned to the new threads. In the Thread class, there is a method that returns an id:

say $*THREAD;my $t1 = Thread.start(sub {});my $t2 = Thread.start(sub {});my $t3 = Thread.start(sub {});say $t1.id();say $t2.id();say $t3.id();

One of the possible outputs of the program is this:

345

Thread identifiers may be used if you want to keep some tracking information in the main thread, for example.

Another way of identifying threads is using names. Names are string labels that you assign to the thread when creating it via the name argument:

my $t1 = Thread.start(name => 'My thread one', sub {});my $t2 = Thread.start(name => ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Learning Perl 6

Learning Perl 6

brian d foy
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 9781787282049Supplemental Content