Subject: | Locking inconsistency |
This program works once, but if you run it straight away again the
message 'parent acuired' appears immediately instead of after 3 seconds.
#!/usr/bin/perl -w
use strict;
use warnings;
use IPC::Semaphore::Concurrency;
if(fork()) {
# parent;
sleep(3);
my $lock = IPC::Semaphore::Concurrency->new(path => $0);
# This should fail, but actually it succeeds
$lock->acquire(wait => 1);
print "parent acquired\n";
$lock->release();
exit();
}
my $lock = IPC::Semaphore::Concurrency->new(path => $0);
$lock->acquire(wait => 1);
print "child acquired\n";
sleep(10);
$lock->release();
print "child freed\n";
sleep(10);