in reply to Re: file reading / writing collisions
in thread file reading / writing collisions

Thanks! just for the sake of curiosity, what happens now when a multiple file write occurs? I mean does the routine simply return 0 or does it wait for the file handle to be available and then write? is there some way to have the routine order a background write in the case of a locked file, so the rest of the script can carry on with what its doing.. or is that a bad idea??
  • Comment on Re^2: file reading / writing collisions

Replies are listed 'Best First'.
Re^3: file reading / writing collisions
by ikegami (Patriarch) on Sep 11, 2007 at 13:42 UTC

    flock: "it waits indefinitely until the lock is granted"

    I don't know of an easy to do what you want without polling. From the looks of it though, your locks are really short lived, so it should not be a problem.

    Update: s/should be/should not be/

Re^3: file reading / writing collisions
by sgt (Deacon) on Sep 11, 2007 at 13:41 UTC

    Well you have to test for your system, but usually perl's flock will block, and you are right it's a problem as you might end up with too many processes! I prefer non-blocking handles and do the polling myself. 'perldoc -f fcntl' will tell you how to set up non-blocking flags.

    cheers --stephan