SlideShare a Scribd company logo
Perl 6 for
Concurrency and
Parallel Computing
or
Parallel Features

of Perl 6
The Parallel

Features

of the Perl Six
Parallel Futures

of Perl 6
Foreword
Interviews for
Pragmatic Perl
in 2013–2015
Perl 6 for Concurrency and Parallel Computing
What is the most important
feature of the programming
languages in the future?
Q:
I don’t knowA:
No idea (2 answers)
There’s no good answerA:
No idea (2 answers)
Natural-like languageA:
Syntax features (1/3)
MinimalismA:
Syntax features (2/3)
ExtendabilityA:
Syntax features (3/3)
Flexible type castingA:
Object system (1/3)
RobustnessA:
Object system (2/3)
Built-in introspectionA:
Object system (3/3)
JVM supportA:
Environment (1/4)
Execution in a browserA:
Environment (2/4)
Language inter-compatibilityA:
Environment (3/4)
EmbeddingA:
Environment (4/4)
CommunityA:
Humanity (1/8)
HumanismA:
Humanity (2/8)
Open sourceA:
Humanity (3/8)
PragmatismA:
Humanity (4/8)
Mind control (sic!)A:
Humanity (5/8)
Expressing things easilyA:
Humanity (6/8)
Domain orientedA:
Humanity (7/8)
UnobtrusivenessA:
Humanity (8/8)
Number 1 answer

Parallelism
ParallelismA:
Parallelism (1/12)
Working with parallel
resources
A:
Parallelism (2/12)
ParallelismA:
Parallelism (3/12)
Good paralleling modelA:
Parallelism (4/12)
Intuitive coroutines and
multi-core support
A:
Parallelism (5/12)
ParallelismA:
Parallelism (6/12)
Safe operation parallelismA:
Parallelism (7/12)
Built-in threadingA:
Parallelism (8/12)
Qualitative abstract threadingA:
Parallelism (9/12)
ParallelismA:
Parallelism (10/12)
Good parallelismA:
Parallelism (11/12)
Multi-taskingA:
Parallelism (12/12)
Back to Perl 6
The idea is

keeping things
transparent
A Perl 6 user
simply uses
concurrency
A Perl 6 compiler
makes it possible
A Perl 6 compiler
makes it possible
The Perl 6 compiler
makes it possible
Running examples
with Rakudo Star
Running examples
with Rakudo Star
on MoarVM
Two kinds

of parallel features
Roughly,
1) implicit
2) explicit
Operators
at a glance
1.
Hyperops
A hyper operator
is a

meta operator
+
operator
+=
meta operator
>>+<<
hyper operator
»+«
hyper operator
>>+
hyper operator
»+
hyper operator
>>+>>
hyper operator
<<+<<
hyper operator
«+«
hyper operator
Perl 6 for Concurrency and Parallel Computing
<<+>>
hyper operator
«+»
hyper operator
<<<>>
hyper operator
«<»
hyper operator
@c = @a >>+<< @b
@c = @a >>+<< @b
@c[0] = @a[0] + @b[0];
@c = @a >>+<< @b
@c[0] = @a[0] + @b[0];
@c[1] = @a[1] + @b[1];
@c = @a >>+<< @b
@c[0] = @a[0] + @b[0];
@c[1] = @a[1] + @b[1];
@c[2] = @a[2] + @b[2];
@c = @a >>+>> 1
@c = @a >>+>> 1
@c[0] = @a[0] + 1;
@c = @a >>+>> 1
@c[0] = @a[0] + 1;
@c[1] = @a[1] + 1;
@c = @a >>+>> 1
@c[0] = @a[0] + 1;
@c[1] = @a[1] + 1;
@c[2] = @a[2] + 1;
2.
Junctions
Or
Quantum
Superpositions
Many values as one
my $j = 1 | 2 | 3 | 5;
my $j = 1 | 2 | 3 | 5;
say 1 if 3 == $j;
my $j = 1 | 2 | 3 | 5;
say 1 if 3 == $j;
my $j = 1 | 2 | 3 | 5;
say 1 if 3 == $j;
my $j = 1 | 2 | 3 | 5;
say 1 if 3 == $j;
}
my $j = 1 | 2 | 3 | 5;
say 1 if 3 == $j;
}1
3.

Feeds
my @a = 1..10;
my @a = 1..10;	
@a ==> grep {$_ mod 2};
my @a = 1..10;	
@a ==> grep {$_ mod 2};	
!
1 3 5 7 9
my @a = 1..10;	
@a 	
==> grep {$_ mod 2}	
==> map {$_ ** 2};
my @a = 1..10;	
@a 	
==> grep {$_ mod 2}	
==> map {$_ ** 2};	
!
1 9 25 49 81
Perl 6 for Concurrency and Parallel Computing
4.

Channels
my $c = Channel.new;
my $c = Channel.new;	
$c.send(42);
my $c = Channel.new;	
$c.send(42);	
say $c.receive;	
!
42
my $ch = Channel.new;
my $ch = Channel.new;	
for <1 3 5 7 9> {	
$ch.send($_);	
}
my $ch = Channel.new;	
for <1 3 5 7 9> {	
$ch.send($_);	
}	
while $ch.poll -> $x {	
say $x;	
}
5.

Promises
my $p = Promise.new;
my $p = Promise.new;	
say $p.status;

Planned
my $p = Promise.new;	
$p.keep;
my $p = Promise.new;	
$p.keep;	
say $p.status;	
!
Kept
my $p = Promise.new;	
$p.break;
my $p = Promise.new;	
$p.break;	
say $p.status;	
!
Broken
Factory methods
start
my $p = start {42};
my $p = start {42};

say $p.WHAT;

(Promise)
my $p1 = start {sleep 2};
my $p1 = start {sleep 2};	
my $p2 = start {sleep 2};
my $p1 = start {sleep 2};	
say $p1.status;	
my $p2 = start {sleep 2};	
say $p2.status;
my $p1 = start {sleep 2};	
say $p1.status;	
my $p2 = start {sleep 2};	
say $p2.status;	
!
Planned	
Planned
my $p1 = start {sleep 2};	
my $p2 = start {sleep 2};	
sleep 3;
my $p1 = start {sleep 2};	
my $p2 = start {sleep 2};	
sleep 3;	
say $p1.status;	
say $p2.status;
my $p1 = start {sleep 2};	
my $p2 = start {sleep 2};	
sleep 3;	
say $p1.status	
say $p2.status	
Kept	
Kept
start

in a thread
in
my $p = Promise.in(3);
my $p = Promise.in(3);	
!
for 1..5 {	
say "$_ {$p.status}";

sleep 1;	
}
my $p = Promise.in(3);	
!
for 1..5 {	
say "$_ {$p.status}";

sleep 1;	
}
1 Planned
1 Planned	
2 Planned
1 Planned	
2 Planned	
3 Planned
1 Planned	
2 Planned	
3 Planned	
4 Kept
1 Planned	
2 Planned	
3 Planned	
4 Kept	
5 Kept
Example:

Sleep Sort
!
for @*ARGS -> $a {	
	
!
!
!
!
}
!
for @*ARGS -> $a {	
	
!
!
!
!
}
!
for @*ARGS -> $a {	
@promises.push(	
Promise.in($a).then({	
say $a;	
})	
);	
}	
!
await(|@promises);
my @promises;	
for @*ARGS -> $a {	
@promises.push(	
Promise.in($a).then({	
say $a;	
})	
);	
}	
!
await(|@promises);
my @promises;	
for @*ARGS -> $a {	
@promises.push(	
Promise.in($a).then({	
say $a;	
})	
);	
}	
!
await(|@promises);
my @promises;	
for @*ARGS -> $a {	
@promises.push(	
Promise.in($a).then({	
say $a;	
})	
);	
}	
!
await(|@promises);
my @promises;	
for @*ARGS -> $a {	
@promises.push(	
Promise.in($a).then({	
say $a;	
})	
);	
}	
!
await(|@promises);
$ ./sleep-sort.pl
$ ./sleep-sort.pl 3 1 2
$ ./sleep-sort.pl 3 1 2	
1
$ ./sleep-sort.pl 3 1 2	
1	
2
$ ./sleep-sort.pl 3 1 2	
1	
2	
3
Home work:

Channels inside
Promises
More:

Schedulers
More:

Suppliers
More:

I/O and Suppliers
More:

Signals
More:

Threads
More:

Atomic
More:

Locks
More:

Semaphores
__END__
Andrew Shitov
andy@shitov.ru April 2015

More Related Content

KEY
Perl 6 talk
PDF
Creating a compiler in Perl 6
PDF
The Perl6 Type System
PDF
Perl6 in-production
PDF
The Joy of Smartmatch
PDF
Perl 6 by example
PDF
Perl6 one-liners
PDF
Perl 6 in Context
Perl 6 talk
Creating a compiler in Perl 6
The Perl6 Type System
Perl6 in-production
The Joy of Smartmatch
Perl 6 by example
Perl6 one-liners
Perl 6 in Context

What's hot (20)

PDF
Wx::Perl::Smart
KEY
Perl세미나
PDF
Functional Structures in PHP
PDF
I, For One, Welcome Our New Perl6 Overlords
PDF
Learning Perl 6
PDF
Benchmarking Perl (Chicago UniForum 2006)
PDF
Perl세미나
PDF
Perl 5.10 for People Who Aren't Totally Insane
PDF
Learning Perl 6 (NPW 2007)
PDF
Zend Certification Preparation Tutorial
PPTX
Php 2
PDF
Improving Dev Assistant
PDF
Good Evils In Perl
PDF
Business Rules with Brick
ODP
Intermediate Perl
ODP
Advanced Perl Techniques
PPT
Functional Pe(a)rls version 2
PDF
Introdução ao Perl 6
ODP
Introduction to Perl
PDF
Introduction to Perl
Wx::Perl::Smart
Perl세미나
Functional Structures in PHP
I, For One, Welcome Our New Perl6 Overlords
Learning Perl 6
Benchmarking Perl (Chicago UniForum 2006)
Perl세미나
Perl 5.10 for People Who Aren't Totally Insane
Learning Perl 6 (NPW 2007)
Zend Certification Preparation Tutorial
Php 2
Improving Dev Assistant
Good Evils In Perl
Business Rules with Brick
Intermediate Perl
Advanced Perl Techniques
Functional Pe(a)rls version 2
Introdução ao Perl 6
Introduction to Perl
Introduction to Perl
Ad

Similar to Perl 6 for Concurrency and Parallel Computing (20)

PPTX
An introduction to Raku
PPTX
Perl6 a whistle stop tour
PDF
Perl6 a whistle stop tour
KEY
Good Evils In Perl (Yapc Asia)
PPTX
Distributed Applications with Perl & Gearman
KEY
Concurrency in ruby
PPTX
Perl: Coro asynchronous
PDF
Qore for the Perl Programmer
PDF
Ruby's Concurrency Management: Now and Future
KEY
Ruby 1.9 Fibers
ODP
What's new in Perl 5.10?
PDF
Concurrent and Distributed Applications with Akka, Java and Scala
PDF
Dataflow: Declarative concurrency in Ruby
PPT
Reliable and Concurrent Software - Erlang
PDF
Gearman and Perl
PDF
Concurrency: Rubies, Plural
PDF
Concurrency: Rubies, plural
PPT
Writing Prefork Workers / Servers
PDF
Asynchronous Programming FTW! 2 (with AnyEvent)
An introduction to Raku
Perl6 a whistle stop tour
Perl6 a whistle stop tour
Good Evils In Perl (Yapc Asia)
Distributed Applications with Perl & Gearman
Concurrency in ruby
Perl: Coro asynchronous
Qore for the Perl Programmer
Ruby's Concurrency Management: Now and Future
Ruby 1.9 Fibers
What's new in Perl 5.10?
Concurrent and Distributed Applications with Akka, Java and Scala
Dataflow: Declarative concurrency in Ruby
Reliable and Concurrent Software - Erlang
Gearman and Perl
Concurrency: Rubies, Plural
Concurrency: Rubies, plural
Writing Prefork Workers / Servers
Asynchronous Programming FTW! 2 (with AnyEvent)
Ad

More from Andrew Shitov (20)

PDF
Perl jobs market in 2024, how good is it?
PPTX
Fun with Raspberry PI (and Perl)
PDF
Параллельные вычисления в Perl 6
PDF
AllPerlBooks.com
PDF
YAPC::Europe 2013
PDF
Perl 7, the story of
PDF
Язык программирования Go для Perl-программистов
PDF
Как очистить массив
PDF
What's new in Perl 5.14
PDF
Что нового в Perl 5.14
PDF
Perl6 grammars
PDF
Text in search queries with examples in Perl 6
PDF
There's more than one way to empty it
PDF
How to clean an array
PDF
Perl 5.10 и 5.12
PDF
Say Perl на весь мир
PDF
Personal Perl 6 compiler
PDF
Perl 5.10 in 2010
PDF
Perl 5.10 в 2010-м
PDF
‎Откуда узнать про Perl 6‎
Perl jobs market in 2024, how good is it?
Fun with Raspberry PI (and Perl)
Параллельные вычисления в Perl 6
AllPerlBooks.com
YAPC::Europe 2013
Perl 7, the story of
Язык программирования Go для Perl-программистов
Как очистить массив
What's new in Perl 5.14
Что нового в Perl 5.14
Perl6 grammars
Text in search queries with examples in Perl 6
There's more than one way to empty it
How to clean an array
Perl 5.10 и 5.12
Say Perl на весь мир
Personal Perl 6 compiler
Perl 5.10 in 2010
Perl 5.10 в 2010-м
‎Откуда узнать про Perl 6‎

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation theory and applications.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
Encapsulation theory and applications.pdf
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Perl 6 for Concurrency and Parallel Computing