On 6/6/06, Chas Owens <[EMAIL PROTECTED]> wrote:
On 6/6/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
You may want to use the non-blocking flock instead: my $tries; for $tries (0 .. $maxtries) { break unless flock (SOCKLOCK,LOCK_EX | LOCK_NB); } die "Could not get an exclusive lock: $!" if $tries == $maxtries;
Perl doesn't have 'break'; I think you mean 'last'. And instead of 'unless', I think you mean 'if'. But this solution is a "busy wait": You're keeping the CPU busy during the retries (which is one more than $maxtries). Instead, use sleep() or the four-argument select() to let other processes use the CPU while you're waiting. As to the original problem, some systems may not support using alarm() to interrupt system calls like flock(), because (I believe) of the way that flock() is emulated. So polling, as you're suggesting, is probably the best solution in that case. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>