On Wednesday, July 17, 2002, at 07:04 , George Schlossnagle wrote:

>>> The main problem appears to be that instead of taking a different branch
>>> if open() or flock() fails you continue on as if they had succeeded.
>
> flock($fh,LOCK_EX ) is a blocking call, so it won't return until the lock 
> is available.

in lieu of going to semaphores... { not a bad solution for most }

{ there is also a race in there for 'grab the semaphore' but it
is probably still better than most solutions... }

you can get round that with an 'alarm()' - something on the form

        my $timeout=5;
        my $getLock=1;
        my $alarmFlag=0;

        local $SIG{ALRM} = sub { $alarmFlag=1;}
        while( $getLock ) {

                open(FH,....) or die ....;
                 alarm $timeout;
                flock(....)
                alarm 0;

                if( $alarmFlag) {
                        $alarmFlag=0;
                        close(FH);
                }else {
                        $getLock=0;
                }
        }

and/or stuff that in an eval block, and..... yadda yadda yadda

This way either you get in and out of there quickly or
block - but in a way that does not have the file open...
one is still in a race condition...

the other is to go with the 'symbolic link' type of trick of the
form of $filename.lockget -> $filename - and everyone checks
for the existence of that file first.... to try to avoid the
open for the flock()....


ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to