in reply to Frustration with changing lock type
Hmm, a quick test shows that I can quite happily downgrade a flock()-style lock on my Linux system without first releasing it. However perldoc -f flock shows a lot of O/S-specific (or rather, emulation-specific) caveats, and I imagine you're getting a different emulation under Win32.
One approach would be to append your process data to the file while you have the exclusive lock, then after unlocking and reacquiring a shared lock verify that yours is still the last line in the file. If it isn't, you must then unlock and go back to the beginning again.
With this approach you might also want to reduce the risk of runaway on a busy system by checking the last modified time and sleeping for a second or two before trying to acquire the exclusive lock if it has only just changed.
If you get the shared lock while your process is still the last named, you can then truncate the file back to containing just one line.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Frustration with changing lock type
by demerphq (Chancellor) on Apr 14, 2004 at 12:37 UTC | |
by hv (Prior) on Apr 14, 2004 at 12:47 UTC | |
by demerphq (Chancellor) on Apr 14, 2004 at 12:53 UTC | |
by hv (Prior) on Apr 14, 2004 at 13:02 UTC | |
by tye (Sage) on Apr 14, 2004 at 15:11 UTC |