Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Introduce "is cas" variable trait
  • Loading branch information
lizmat committed Nov 11, 2013
1 parent 98c34a7 commit 82ae35f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions S17-concurrency.pod
Expand Up @@ -792,6 +792,15 @@ parenthesis around the operator:

$count (+=) 1; # cas $count, { $_ + 1 }

However, in concurrent programming, you want to make sure that B<all> updates
to a variable being accessed from multiple concurrent tasks, are wrapped in a
C<cas>. To mark accesses to a variable thusly, you can use the C<is cas>
trait.

my $count is cas; # $a++, $a ~= "foo", $a += 5, etc.
my @done is cas; # @done.push, @done.pop, etc.
my %objects is cas; # %objects{.WHAT}.push($_), etc.

Another example, implementing a top-5 news headlines list to be accessed and
updated without ever locking, as:

Expand Down

0 comments on commit 82ae35f

Please sign in to comment.