http://qs1969.pair.com?node_id=1043858

The_Dj has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks.
I can't believe no-one has solved this so it must be that my google-fu has failed me.

Simple lockfile for concurrency.
use Fcntl ':flock'; open (LF,'>>',$file); flock (LF,LOCK_EX|LOCK_NB) or die "Just one at a time, please"; select LF; $|=1; print "$$\n"; select STDOUT; ...snip... truncate LF,0; close LF; unlink $file; __END__
This is on Windows 2003/ActivePerl 5.8, and the locking works.
The problem is...
Sometimes the process needs to be killed, and for that someone needs to read that file.
Notepad works fine, but for some reason the people who do this try to open the file in vim (despite being windows people :-|)
Vim honors the exclusive lock, and shows no content.
Vim will read the file if it's only a shared lock.

If I just flock (LF,LOCK_SH); the exclusive lock remains.
But if I flock (LF,LOCK_UN); flock(LF,LOCK_SH); then I risk a race condition.
A random stab at flock (LF,LOCK_UN|LOCK_SH) didn't work either.
I can't install extra modules because reasons.

Thanks for any help!