sub atomic-fetch
1 | class Scalar |
1.1 | (Scalar) sub atomic-fetch |
2 | class atomicint |
2.1 | (atomicint) sub atomic-fetch |
Documentation for sub atomic-fetch
assembled from the following types:
class Scalar
From Scalar
(Scalar) sub atomic-fetch
multi sub atomic-fetch( is rw)
Performs an atomic read of the value in the Scalar
$target
and returns the read value. Using this routine instead of simply using the variable ensures that the latest update to the variable from other threads will be seen, both by doing any required hardware barriers and also preventing the compiler from lifting reads. For example:
my = False;startuntil atomic-fetch()
Is certain to terminate, while in:
my = False;startuntil
It would be legal for a compiler to observe that $started
is not updated in the loop, and so lift the read out of the loop, thus causing the program to never terminate.
class atomicint
From atomicint
(atomicint) sub atomic-fetch
Defined as:
multi sub atomic-fetch(atomicint $ is rw)
Performs an atomic read of a native integer, which may live in a lexical, attribute, or native array element. Using this routine instead of simply using the variable ensures that the latest update to the variable from other threads will be seen, both by doing any required hardware barriers and also preventing the compiler from lifting reads. For example:
my atomicint = 0;startwhile atomic-fetch() == 0
Is certain to terminate, while in:
my atomicint = 0;startwhile == 0
It would be legal for a compiler to observe that $i
is not updated in the loop, and so lift the read out of the loop, thus causing the program to never terminate.