in reply to Re: Locking a script
in thread Locking a script

You would have a serious race condition.

Invocation 1 comes along, opens the file, and flocks it.

Invocation 2 comes along, opens the file, and blocks on the flock.

Invocation 1 leaves and unlinks the file, dropping the lock it had.

Invocation 2 gets its lock on a temporary that only will exist until Invocation 2 is done.

Invocation 3 comes along, sees no file, creates, flocks, and now Invocations 2 and 3 are running in parallel...

(This is all with Unix filesystem semantics of course.)

Replies are listed 'Best First'.
RE: RE (tilly) 2 Locking a script
by ChOas (Curate) on Oct 18, 2000 at 15:24 UTC
    Okay, okay....

    Wasn't thinking heavy duty progamming for a sec. ;)))
    Dining Philosophers 'n stuff...

    How about a semaphore ?
    perldoc perlipc might give some clues...