IPC and counters
Simon Wistow
simon at thegestalt.org
Wed Oct 15 01:01:10 BST 2008
On Wed, Oct 15, 2008 at 12:08:43AM +0100, me said:
Tell a lie, what I want is
Parent:
my $id = $message->id;
my $n = scalar(@children);
my $sem = IPC::Semaphore->new(IPC_PRIVATE, 2, IPC_CREAT);
$sem->setall(1, $n-1);
foreach my $child (@children) {
$child->send($message, $sem->id);
}
Child:
my ($msg, $sem_id) = get_message();
my $sem = IPC::Semaphore->new($sem_id);
if (0 == $sem->op(0, -1, IPC_NOWAIT)) {
do_something($message);
}
# If we're the last then clean up
if (EAGAIN == $sem->op(1,-1, IPC_NOWAIT)) {
$sem->remove;
}
More information about the london.pm
mailing list