Hi There:
I wonder if there are any solution to this. I have 5 clients forked and the 6 suppose to release the lock.
Don't know why if I have a sleep in the client script, all the client are struck in the semaphore-> wait () deadlock.
or process does not know how to wake up. I am run ActiveState Perl.
I need to sleep x seconds each time. If I don't sleep it is fine. Any solutions ?
Thanks in advance.
Wayne.
for $j (1 .. 6)
{
if( $parent == $$)
{
if( defined (my $pid = fork() ) ){
if( ! $pid){
##if $pid ==0 then this is the child process
&handleChild($j);
exit;
}
}
else
{
warn "something went wrong with fork $!";
}
}
}
sub handleChild {
my $cid = shift;
my $semaphore;
# Each child process run this code.
my $i = 0;
if ($cid == (6))
{
if ($UseMaxLog == 1)
{
$semaphore = getSemaphore( 0, $MaxClients , "mySem");
$semaphore->release(1);
print "\nClient $cid release lock\n";
}
}
else
{
do { # do forever or NumQueries times.
$i++;
process_query($i,$cid);
} while (($doforever == 1) || ($i < $NumQueries));
}
}
sub process_query
{
my ($query_index,$client_index) = @_;
foreach $query (keys %queries) {
$param="";
foreach $option ( keys %{ $queries{$query}} ){
`sleep 5`; # all client waiting below dead because of sleep
$semaphore = getSemaphore( 0, $MaxClients , "mySem");
print "Client $client_index waiting for lock\n";
$semaphore->wait(); # all clients waiting here !!!!
print "Client $client_index releasing lock\n";
$semaphore->release(1);
}
}
}
Thanks,
Wayne Tran
Software Developer
McKesson Medical Imaging
Phone: (604) 279-5422 ext 442
E-mail: [EMAIL PROTECTED]