File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ hyper-operators, autothreading junctions?
25
25
26
26
= end comment
27
27
28
- Additionally certain Perl features may implicitly operate in am asynchronous
28
+ Additionally certain Perl features may implicitly operate in an asynchronous
29
29
fashion, so in order to ensure predictable interoperation with these features
30
30
user code should, where possible, avoid the lower level concurrency APIs
31
31
(i.e. L < Thread > and L < Scheduler > ) and use the higher-level interfaces.
@@ -648,4 +648,23 @@ C<protect> returns whatever the code block returns.
648
648
Because C < protect > will block any threads that are waiting to execute
649
649
the critical section the code should be as quick as possible.
650
650
651
+ = head1 Safety Concerns
652
+
653
+ Some shared data concurrency issues are less obvious than others.
654
+ For a good general write-up on this subject see this L < blog post|https://6guts.wordpress.com/2014/04/17/racing-to-writeness-to-wrongness-leads/ > .
655
+
656
+ One particular issue of note is when container autovivification or extension
657
+ takes place. When an L < Array > or a L < Hash > entry is initially assigned the
658
+ underlying structure is altered and that operation is not async safe. For
659
+ example, in this code:
660
+
661
+ my @array;
662
+ my $slot := @array[20];
663
+ $slot = 'foo';
664
+
665
+ The third line is the critical section as that is when the array is extended.
666
+ The simplest fix is to use a <Lock> to protect the critical section . A
667
+ possibly better fix would be to refactor the code so that sharing a container
668
+ is not necessary.
669
+
651
670
= end pod
You can’t perform that action at this time.
0 commit comments