in reply to Re: Filename from filehandle?
in thread Filename from filehandle?

Could you talk more about "And beware of flock'ing filehandles that are already open... "?

I don't think I've ever applied a lock routine more than once. But now you've got my curiousity. What symptoms might occur if at some point I mess up and flock a file for the second time.

Sign me curious
Claude

Replies are listed 'Best First'.
Re (tilly) 3: Filename from filehandle?
by tilly (Archbishop) on Apr 25, 2001 at 02:25 UTC
    Here is the idea of what can happen:
    STEP 1: Wait for the first lock to be lost. STEP 2: Lose the first lock STEP 3: (Why don't we get here?)...
    This state of affairs is known as a "deadlock" and is usually considered Not Good.
Re: Re: Re: Filename from filehandle?
by clintp (Curate) on Apr 25, 2001 at 05:01 UTC
    Filehandles that are already opened (especially for writing) have may have already been modified, before the lock was applied. Consider:
    open(FOO, ">/tmp/foo") || die; # You've altered the file! flock(FOO, LOCK_EX) || warn; # And now you bother to lock it?
    Yeah, it's silly. But you'd be amazed at how often it happens.