Data-Stack-Shared
view release on metacpan or search on metacpan
"empty â writing â filled", and a popper transitions it through "filled
â reading â empty" with the generation bumped on completion. A consumer
that claims position "t-1" via the "top" CAS therefore always observes
the matching pusher's transition to "filled" before reading the value.
"peek" is a seqlock-style read: it retries if the slot transitions
during the read and returns false if the top changes concurrently beyond
the retry budget.
"drain" is safe under concurrent "push"/"pop", but it spin-waits on
slots whose pusher is mid-publish; a pusher crash between its position
CAS and the publish leaves drain blocked on that slot. Use "drain" for
orderly draining, not as a crash-recovery primitive.
Compatibility
File format bumped to v2 in this release (per-slot control array added
for MPMC safety). Opening a v1 file (magic "STK1") created by
Data::Stack::Shared "<= 0.02" will croak on header validation. Re-create
the stack with the new version; anonymous and memfd-backed usage is
unaffected.
Variants
lib/Data/Stack/Shared.pm view on Meta::CPAN
C<empty â writing â filled>, and a popper transitions it through
C<filled â reading â empty> with the generation bumped on completion.
A consumer that claims position C<t-1> via the C<top> CAS therefore
always observes the matching pusher's transition to C<filled> before
reading the value. C<peek> is a seqlock-style read: it retries if the
slot transitions during the read and returns false if the top changes
concurrently beyond the retry budget.
C<drain> is safe under concurrent C<push>/C<pop>, but it spin-waits on
slots whose pusher is mid-publish; a pusher crash between its position
CAS and the publish leaves drain blocked on that slot. Use C<drain> for
orderly draining, not as a crash-recovery primitive.
=head2 Compatibility
File format bumped to v2 in this release (per-slot control array added
for MPMC safety). Opening a v1 file (magic C<STK1>) created by
Data::Stack::Shared C<E<lt>= 0.02> will croak on header validation.
Re-create the stack with the new version; anonymous and memfd-backed
usage is unaffected.
xt/signal_during_wait.t view on Meta::CPAN
use Test::More;
use POSIX qw(_exit);
use Time::HiRes qw(time);
use Data::Stack::Shared;
plan skip_all => 'AUTHOR_TESTING not set' unless $ENV{AUTHOR_TESTING};
# A SIGUSR1 while a process is parked in pop_wait must cleanly interrupt
# the futex, re-check the predicate, and (since no data arrived) continue
# waiting for the FULL remaining window. Wall-time assertion: total time
# spent blocked â timeout, not just up-to-signal-arrival.
my $s = Data::Stack::Shared::Int->new(undef, 4);
my $TIMEOUT = 2.0;
pipe(my $rd, my $wr) or die $!;
my $pid = fork // die;
if ($pid == 0) {
close $rd;
local $SIG{USR1} = sub { }; # install handler (EINTR)
my $t0 = time;
( run in 2.209 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )