Skip to content

Commit

Permalink
state that state variables are shared between threads
Browse files Browse the repository at this point in the history
  • Loading branch information
gfldex committed May 24, 2016
1 parent a4576d6 commit 6366e6b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/Language/variables.pod
Expand Up @@ -578,6 +578,18 @@ Please note that many operators come with implicit binding, what will lead to ac
f for 1..3;
dd @a; # «Array $var = $[:k1(3), :k2(3), :k3(3)]»
All state variables are shared between threads. The result can be undesired or
dangerous.
sub code(){ state $i = 0; say ++$i; $i };
await
start { loop { last if code() >= 5 } },
start { loop { last if code() >= 5 } };
# OUTPUT«1␤2␤3␤4␤4␤3␤5␤»
# OUTPUT«2␤1␤3␤4␤5␤»
# many other more or less odd variations can be produced
=head3 The C<$> Variable
As well as explicitly declared named state variables C<$> can be used
Expand Down

0 comments on commit 6366e6b

Please sign in to comment.