B
badarisj
folks,
i wrote a small test program to test the advisory locking
using the routines from Storable module.
in my program, the parent process gets
a shared-lock by invoking 'lock_retrieve' function.
the child process attempts to get the exclusive lock
by calling lock_store.
i expected the child's lock_store be blocked
till the parent exits and NOT see the message with ERROR prefix.
but to my surprise, i DO see the message with ERROR prefix
BEFORE the parent process exited.
what am i missing here?
thanks,
-badari
output on my screen:
================
squirrel 23 % ./storable_locking
The parent process got shared/read lock
ERROR: How could i store if there was a shared lock gotten by my parent
<the prompt takes quite sometime to come back owing to sleep>
the test program:
=============
#!/usr/cisco/bin/perl5.8 -w
use Storable qw(lock_store lock_nstore lock_retrieve);
my $struct =
{
"field1" => "val1"
};
my $file = 'struct_store';
# store the struct
lock_nstore $struct, $file;
if ( my $pid = fork() ) {
# parent
$struct = lock_retrieve $file;
print "The parent process got shared/read lock\n";
sleep(1000);
print "parent got out of sleep and exiting.";
} else {
#child
sleep(10);
$struct->{field1} = 'new val';
my $hashref = lock_store $struct,$file;
print "ERROR: How could i store if there was a shared lock gotten
by my parent\n";
}
i wrote a small test program to test the advisory locking
using the routines from Storable module.
in my program, the parent process gets
a shared-lock by invoking 'lock_retrieve' function.
the child process attempts to get the exclusive lock
by calling lock_store.
i expected the child's lock_store be blocked
till the parent exits and NOT see the message with ERROR prefix.
but to my surprise, i DO see the message with ERROR prefix
BEFORE the parent process exited.
what am i missing here?
thanks,
-badari
output on my screen:
================
squirrel 23 % ./storable_locking
The parent process got shared/read lock
ERROR: How could i store if there was a shared lock gotten by my parent
<the prompt takes quite sometime to come back owing to sleep>
the test program:
=============
#!/usr/cisco/bin/perl5.8 -w
use Storable qw(lock_store lock_nstore lock_retrieve);
my $struct =
{
"field1" => "val1"
};
my $file = 'struct_store';
# store the struct
lock_nstore $struct, $file;
if ( my $pid = fork() ) {
# parent
$struct = lock_retrieve $file;
print "The parent process got shared/read lock\n";
sleep(1000);
print "parent got out of sleep and exiting.";
} else {
#child
sleep(10);
$struct->{field1} = 'new val';
my $hashref = lock_store $struct,$file;
print "ERROR: How could i store if there was a shared lock gotten
by my parent\n";
}