- Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathcas-loop-int.t
27 lines (23 loc) · 653 Bytes
/
cas-loop-int.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
useTest;
plan7;
# Basic sanity
{
my atomicint $value=21;
myint$was;
ok cas($value, { $was=$_; 2*$_ }) ==42,
'Looping form of CAS returns what was installed';
ok$was==21, 'The block was called with the original value';
is$value, 42, 'The value was updated with the correct value';
}
# Make sure we really do it atomic.
for1..4->$attempt {
my$total=0;
awaitstart {
for1..10000->$i {
cas $total, ->$cur { $cur+$i }
}
} xx4;
is$total, 4* [+](1..10000),
"Block form of CAS on integer lexical works ($attempt)";
}
# vim: expandtab shiftwidth=4