Data-Buffer-Shared

 view release on metacpan or  search on metacpan

eg/ev_eventfd.pl  view on Meta::CPAN

#!/usr/bin/env perl
# EV event loop integration via eventfd
#
# The eventfd descriptor is pollable — plug it directly into EV::io
# for non-blocking notifications without busy-wait.
#
# Requires: EV
use strict;
use warnings;
use POSIX qw(_exit);

use Data::Buffer::Shared::I64;

my $buf = Data::Buffer::Shared::I64->new_anon(10);
my $efd = $buf->create_eventfd;

t/08-eventfd.t  view on Meta::CPAN


    my $pid = fork();
    if ($pid == 0) {
        # child: write data then notify
        $buf->set(0, 42);
        $buf->notify;
        _exit(0);
    }

    # parent: wait for notification, then read
    # busy-wait with short sleep since eventfd is nonblocking
    my $val;
    for (1..100) {
        $val = $buf->wait_notify;
        last if defined $val;
        select(undef, undef, undef, 0.01);
    }
    waitpid($pid, 0);

    ok(defined $val, 'cross-process: received notification');
    is($buf->get(0), 42, 'cross-process: data visible after notify');



( run in 1.258 second using v1.01-cache-2.11-cpan-39bf76dae61 )