September 2017
Beginner
402 pages
9h 52m
English
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 => ...