Perl6-Doc
view release on metacpan or search on metacpan
share/Synopsis/S17-concurrency.pod view on Meta::CPAN
=head2 Coroutines
Coroutines are covered in S07
=head2 Threads
All outside of a thread defined variables are
shared and transactional variables by default
Program will wait for _all_ threads.
Unjoined threads will be joined at the beginning of the END
block batch of the parent thread that spawned them
=head3 Thread creation
A thread will be created using the keyword C<async> followed by
a codeblock being executed in this thread.
my $thr = async {
...do something...
END { }
};
=head3 Thread status and attributes
=over
=item Self reflection
TODO: how you can access thread attributes inside a thread
async {
say "my tid is ", +self;
};
=item started
start time
=item finished
end time
=item waiting
suspended (not diff from block on wakeup signal)
waiting on a handle, a condition, a lock, et cetera
otherwise returns false for running threads
if it's finished then it's Nil
=item current_continuation
the CC currently running in that thread
=item wake_on_readable, wake_on_writable, wake_on
TODO: IO objects and containers gets concurrency love!
$obj.wake_on_either_readable_or_writable_or_passed_time(3); # fixme fixme
$obj.wake_on:{.readable} # busy wait, probably
my @a is Array::Chan = 1..Inf;
async { @a.push(1) };
async { @a.blocking_shift({ ... }) };
async { @a.unshift({ ... }) };
=back
=head3 Thread operators
=over
=item Stringify
Stringify to something sensible (eg. "<Conc:tid=5>");
my $thr = async { ... };
say ~$thr;
=item Numerify
Numify to TIDs (as in pugs)
my $thr = async { ... };
say +$thr;
=item Enumerable
TODO: Enumerable with Conc.list
=back
=head3 Thread methods
=over
=item yield
TODO: Conc.yield (if this is to live but deprecated, maybe call it sleep(0)?)
=item sleep
sleep() always respects other threads, thank you very much
=item join
wait for invocant to finish (always item cxt)
my $thr = async { ... };
$thr.join();
=item die
throw exception in the invocant thread
=item alarm
set up alarms
=item alarms
( run in 2.038 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )