►
Description
Concurrent programming used to be hard. Stefan Schindler is talking about techniques to structure code using ThreadPool and Iterator with rayon.
This talk will teach you the basic building blocks to not get lost in a forest of threads and tasks.
Slides: https://estada.ch/2019/3/20/parallel-programming-in-amsterdam/
Examples: https://github.com/dns2utf8/thread-pools-and-iterators/tree/master/beispiele
ThreadPool: https://crates.io/crates/threadpool
Rayon: https://crates.io/crates/rayon
Questions start at 41:06
B
A
A
A
This
line
describes
Paris,
which
was
in
spring
roll
was
in
the
next
film
will
be
also
in
four,
because
we
have
to
I,
take
two
steps
back
and
look
at
our
project
and
say:
okay,
we
are
doing
the
same
things
wrong
every
time
we
actually
need
the
fixed
time.
So
that's
what
we're
currently
doing
and
by
any
chance
there
will
be
rust,
fest
in
the
Barcelona
in
Spain,
probably
in
September
world
yeah,
you
organize
some
talks.
This
is
an
alternative
festival.
A
A
B
A
A
A
A
A
A
D
C
A
A
bunch
of
problems-
oh
and
I,
use
these
names
here
from
a
book
and
I'm,
not
sure
if
it's
common
around
here,
it's
a
very
funny
book
in
German
mark
will
be
clean.
It's
about
digital
age,
it's
called
quality
level
which
is
Germany
after
they
renamed
themselves.
After
some
political
scandal,
okay
see
also
improved
a
bit
over
time.
A
A
A
A
Yeah
I
will
be
using
this
I
copied
in
this
flag
here
so
that
you
see
you
should
probably
shouldn't
use
it,
but
if
you
ever
get
into
the
case
or
it
generates
cold,
and
it
gives
you
this
ugly
warning,
then
you
can
allow
ugly
code.
There
used
to
be
a
great
link
which
was
allowed
bad
code.
But
then
some
people
know
I
mean
I'm
going
to
attack
something
as
bad
coldest.
A
Okay,
so
how
to
be
iterate
over
a
bow,
easy
peasy
to
see
start
right,
there's
a
problem
with
this
actually
too.
So
one
of
the
problems
is
here.
This
semicolon
is
optional
and
currently
the
return
value
is.
This
expression
returns
something
the
index
increased
and
it
gets
lost
for
now,
but
in
the
future,
there's
a
good
chance
that
this
book
will
return
the
last
of
these
values,
so
that
might
come
in
as
a
problem.
At
some
point,
Plus
this
index
access
might
give
out
of
bounds
index.
So
it's
problem.
C
A
I'll
just
say
for
each
if
you
have
to
be
backwards
compatible
with
all
the
rust
like
14
or
something
like
that,
then
for
each
isn't.
Therefore,
for
each
is
think
122
or
something
like
that
that
there
are
like
two
breaking
points
you
actually
have
to
remember.
So
one
is
113
the
question
mark
operator
and
120
ish
92.
C
A
Have
questions
just
like
we
shout
so:
what's
the
iterator
in
rust,
it's
a
trade
and
that's
all
the
stuff.
We
need
to
know
it's.
The
absolute
minimum
information
iterator
needs
to
fulfill
has
to
have
an
item
this
time
here
makes
it
generic,
although
it
does
the
half
day,
turbo
fish,
syntax
and
then
the
next
big
option
and
option
is
our.
A
A
A
A
Can
enable
and
disable
filters
with
like
two
packs
like
405
all
right-
it's
also
nice
for
the
compiler,
because
it
can
optimize.
You
have
this
functional
style.
That
compiler
knows
you
touch
one
element
at
a
time
and
then
it
can
do
some
hardware,
optimization
and
process
for
element
plus
there's
also
a
great
talk
from
Pascal
headlight.
He
gave
it
in
row,
yeah.
C
A
A
B
A
We
risk
out
of
bounds
annex
so
what
I've
seen
people
do.
Is
they
collect
into
the
vector
to
know
how
long
it
is
and
then
take
another
iterator
to
loop
over
it
again?
That's
when
iterators
our
entity
return,
none
and
anything
so
much
easier,
it's
so
much
easier
to
check
to
return
okay.
So
what
are
we
going
to
do
here?
We
assume
that
every
person
has
just
the
first
name
and
the
surname.
C
A
A
Think
I
was
this
right
there,
okay
and
last
but
not
least,
here
we
unwrap
it
because
now
we
know
that
they
are
there
so
I'm
red
and
into
because,
in
fact
we
didn't
handle
strings
here.
We
have
a
string
here
in
the
name
symbol,
but
the
split
gives
us
so
they
are
used.
So
we
carry
create
an
object.
These
are
smart
pointers
yeah.
A
A
A
B
C
A
If
there
is
an
error,
give
with
the
error,
if
it's
so,
this
gives
us
either
a
correct
list
or
the
first
error
all
right.
So
this
is
Hardy
code
right.
So
let's
improve
it
a
little
bit
so
first,
you
smash,
so
we
can
get
rid
of
the
other
atoms
right
can
match
on
this
tuple
create
person
if
it's
if
it
worked
or
we
can
create
the
error
for
everything
else.
So
this.
A
A
E
A
A
Iterator
and
say:
hey
constructing
my
name,
constructing
a
block
and
then
it
will
attend
one
more
and
then
here
is
a
field
without
a
and
then
depending
on
how
the
format
is
specified,
it
will
either
take
multiple
lines
or
one
by
four
prepended
with
zeros
or
spaces
or
tabs
or
whatever.
You
want
to
say
minute.
This
way,
all
right,
so
so
much
for
the
base.
I
hope
you
weren't
bored.
If
so,
wake
up.
A
Okay,
what
what
are
we
going
to
do?
It's
usually
one
of
these
things,
some
things,
because
you
have
to
generate
lots
of
time
or
maybe
on
the
fly,
messages
or
the
or
all
that
stuff.
That's
real
time,
because
all
the
stuff,
that's
slow
is
usually
solved
good
enough
with
all
the
languages
that
nobody
cares.
C
B
A
A
If
you're
going
too
hard
and
there's
interrupts,
if
you
go
there,
there
is
a
pretty
cool
operating
system.
The
tacos
it's
rust,
based
it
only
works
on
certain
are
microcontrollers,
but
then
you
don't
need
locks
anymore.
So
you
can
have
locks
with
the
interrupt
table.
Manipulate,
interrupts,
table
the
type
system
and
then
get
very
cool.
A
Cindy
is
the
thing
that
I
think
that
look
forward.
So
there
are
some
languages
that
already
do
that,
like
C++,
if
you
use
for
each
or
any
other
algorithms
loop
thingy,
it
will
create
two
nested
loops,
one
for
start
from
zero
to
the
end
and
inside
that
start
from
here
to
four
or
and
then
loop
for
inside
and
then
jump
outside
again
and
what
this
tells
the
compiler
is
hey.
A
A
To
the
most
expensive
part
to
see
if
I
have
a
branch
that
one
arm
of
the
primes
is
like
wait
longer
for
you.
If,
if
statement
has
one
long
part
and
one
short
part,
that's
very
expensive
for
the
graphics
card
of
the
CPU,
we
don't
have
this
problem
because
we
have
SMP
simultaneous
multi-threading
where
you
can
have
stuff
from
independently.
But
now
we
have
to
synchronize
that
the
old
approach
is
the
pool.
We
have
a
list
of
jobs
or
fixed
size
of
workers,
and
then
you
go
out
in
requests
at
the
Apache
web
service.
A
There
are
other
programs
that
we
might
use
is
OpenSSH,
OpenSSH
doesn't
use
Freddy,
that's
a
fork
program.
So
when
you
create
open
an
SSH
connection,
your
connection
gets
forked
away
from
the
server
in
that
smile.
You
can
restart
OpenSSH
server.
We
have
losing
the
connection
because
your
process
is
independent.
C
A
A
A
A
A
A
C
A
Fred's
spawn
and
then
we
have
to
join
that
again
so
when
we
spawn
a
flag
to
get
the
dragon
handling,
if
you
just
have
one
task
that
we
want
to
get
rid
of
and
do
something
else
at
the
maintenance,
sometimes
good
enough,
we
can
also
use
pools
when
we
have
fixed
size
of
workers.
This
is
a
huge
advantage
when
we
have
something
asynchronous
happening
like
an
event
loop,
and
sometimes
you
have
work,
that's
uploaded
to
the
workers
that
over
our
machine.
A
F
A
Rayon
work-stealing
rayon
is
an
iterator
approach.
Where
you
spawn
work
with
either
divide
and
conquer
like
recursion,
then
you
can
have
recursive
function
that
calls
itself
twice.
So
it
can
have
one
task
for
your
own
friend
and
one
task
for
the
others
to
take,
or
we
have
some
indexable
access
to
data
data.
Parallelism
can.
A
A
A
A
A
From
the
crate,
and
with
this
statement
we
have
a
compiler
to
link
it
and
we
use
channel
from
the
standard
library
which
is
always
used,
and
they
say:
ok
for
Merkers,
eight
jobs
can
increment.
This
number,
like
crate,
is
pool
the
old
way,
there's
a
new
way.
The
other
way
where
you
can
select
stuff
like
stack
size
of
the
workers
or
say
hey,
just
make
all
the
detail.
I
don't
want
to
care.
How
many
to
create?
A
A
Okay,
for
underscore
again,
we
ignore
the
index.
We
create
a
range.
This
gives
the
compiler
I'm
going
to
optimize
this.
However,
it
wants-
and
let
me
say:
okay,
we
clone
some
assigning
and
for
everything
shove
it
into
the
pool
with
move
move
statement
here,
it's
important
because
we
want
this
TX
symbol
to
month
to
have
it
gone,
must
be
copied
into
the
fret
and
then
no
longer
accessible
to
our
anything
else.
Area
is
very
simple:
send.
A
This
one,
you
know
unwrapped,
this
is
it's
it's
bigger
brother,
except
it's
a
really
really
nice,
because
if
you
have
release
mode
code-
and
it
just
says,
hey
something
panicked,
then
you
look
at
it
like
sure,
a
panic,
an
option
line
for
hundreds,
something
in
standard
library.
Thank
you
that
doesn't
help
at
all,
but
with
Excel
you
can
have
a
message
and
I
usually
start
them
with
unable
something
something
something
so
I
must
have
Ricky
unable
to
write
to
channel
on
this
I
brought
it's
there
for.
A
A
A
A
D
A
There
used
to
be
this
recommendation
that
you
should
use
take,
but
we
take.
You
can
end
a
traitor
after
and
elements,
but
this
gives
you
a
problem
if
your
pool
yields
multiple
things
like
I
wrote,
the
front,
end
generator
ones
and
a
what
wanted
to
have
no
redundant
files,
because
I
wasn't
ready
thousands
of
times
so.
B
E
A
B
C
A
This
has
to
travel
back
and
forth.
That's
why
if
you
ever
have
a
big
system
and
you're
still
doing
harder
by
yourself
and
you
have
beard
memory,
latency
issues
try
to
have
more
memory,
but
not
too
much,
because
then
it
gets
low
and
in
this
way,
whether
it
happen
because
amy
has
more
memories.
Okay,
anyhow,
so
what
this
code
does
is
it
gives
every
job
here?
Is
your
input
from
the
last
one?
And
here
is
your
output
to
the
next
one,
so
you
chain
them
together
and
the.
C
A
So,
from
from
a
hardware
point
of
view
became
imagine,
this
is
fiddled
your
CPU
with
one
thread
per
physical
unit
and
then
just
let
them
run
for
20
million
iterations
and
then,
after
that,
they
will
start
to
collect
in,
like
a
wave
over
the
whole
silicon
down
to
the
last
one,
all
the
results,
but
at
the
same
time,
on
the
top,
they
start
running
again.
So
you
get
still
waves
over.
A
A
A
Imagine
you
start
with
regular
code.
You
have
some
vector
some
pictures.
Maybe
they
are
not.
Actually
the
pictures
were
passed
to
the
pictures
of
just
metadata
that
you
have
on
them
and
you
process
them
by
getting
the
length
and
then
I
don't
know,
maybe
get
something
back
from
there
or
if
you
have.
The
pictures
are
the
receiving
ends
of
channels.
A
A
Metadata
all
pictures
that
works
it
fails
when
some
pictures
don't
get
generated
yeah.
So
we
can
use
the
iterator
instead
solve
some
problems.
Then
this
is
still
pretty
ugly.
So,
let's
get
rid
of
that,
we
can
say
for
each
okay,
then
at
some
point
you
might
say
maybe
I
want
to
fill
there.
Sometimes
the
pictures
are
not
wanted
in
this
collection.
So.
A
B
A
C
A
A
A
Maybe
so
maybe
you
have
all
your
CPUs
maxed
out,
maybe
you
decided
I
have
multiple
pools,
maybe
I
use
on
your
fourth
for
this
task
and
fourth
for
another
task,
but
it
doesn't
really
matter
because
what
you
get
here
is
an
potentially
infinite
sequence.
So
it
doesn't
make
much
sense
here
to
paralyze
this,
because
we
only
like
look
at
it
have
an
error
in
the
processing
before.
But
if
we
did
something
else
here,
we
could.
E
A
We
could
have
a
series
streaming
in,
have
them
automatically
distribute
over
our
pool
and,
at
the
end,
still
get
our
normal
connection
yeah,
but
with
lots
of
type
system
working
for
you
and
giving
that
away.
Because
you
don't
need
to
you
don't
need
to
know
right,
you
don't
care,
because
it's
an
infinite
sequence
anyway.
So.
A
A
F
A
A
A
The
standard
answer
to
any
performance
problem
before
paralyzing
anything
should
be
release
interval.
It
gives
you
speed
up
from
20
to
400
times,
depending
on
what
you're
doing.
That's
just
insane.
You
do
nothing
else.
You
can't
have
the
serial
code
as
before.
Sometimes
human
code
is
still
faster
because
of
all
the
branch
prediction
and
stuff
like
that,
when
you
want
to
know
what
was
going
on
counters,
selenium
I
used
to.
B
A
Per
task
and
timers
as
well,
what
didn't
work
very
well
was
having
my
custom
timer,
so
I
read
about
the
system
clock
and
how
it
might
change
our
antique.
You
may
slowly
shift
it
over
the
day,
but
for
for
my
purposes
they
never
shifted
so
much
that
it
affected
me
and
at
the
end
it
was
so
horrible
to
get
it
right.
D
A
D
A
A
Then
was
something
like
the
overhead
of
communicating
that
this
kind
of
talk
has
to
be
aborted,
is
so
much
higher
that
it's
just
not
worth
it
in
in
the
general
case.
So
when
you
want
to
have
control
over
that,
you
have
to
have
some
abort
signal.
I
mean
you're
at
the
point
where
you're
like
okay
do
I
still
use
rayon
the
frat
cool
for
my
experiments.
I
was
using
the
fretboard
already
so
I
have
just
added
a
single
yeah
skip
parts
that
have
a
function
with
like
four
parts
in
it
so
skip.
A
A
A
B
E
E
Of
these
repetitions
are
resolved,
though,
and
others
are
fast,
it
would
be
a
priority
in
which
I
can
get
the
fastest
computational,
whatever
I'm
working
is
that
it
seems
to
me
that
I
have
to
wait
until
everything
finishes:
people
ready
for
like
the
grind.
Yes,
these
are
some
patterns
with
great.
You
know
something
that
I
can
get
fresh
reputation
and
go
as
fast
as
possible
than
me.
Maybe
you
know,
but.
A
A
A
A
So
we
used
the
bench
tools
of
rust
nightly
and
then
just
iterated
over
it.
It
has
some
some
clever
logic
to
figure
out
how
many
million
times
it
has
to
run.
Then
we
realize
the
funnel
generation
process
inside
the
image
lab.
They
already
use
the
trail,
so
they
paralyze
the
image
resizing
already
eternally,
so
that
task
is
happening,
but
your
task
of
analyzing,
the
image
for
metadata
or
artifacts,
or
something
like
that.
It's
also
running
concurrently
on
that
pool,
so
some
tasks
for
out
of
the
pool
and
some
others
are
cute
back
and
forth.
A
So
yes,
if
you
have
an
event
loop
dispatching,
although
HTTP
requests
into
the
pool
there
will
be
only
one
pool
executing
all
the
queries
might
be
a
problem,
because
your
new
short
request
might
stand
in
queue
behind
four
or
five
longer
ones,
but
after
day,
if
you
have
like
most
of
your
jobs
are
short
and
they
come
in
asynchronously
and
some
of
them
are
long
and
the
long
months
are
not
too
close
together.
Then.