in reply to Why no LockFile() in Win32API::File ?
However, if you need the emulation, then it already exists in and is exported by perl58.dll under the name win32_flock. It can be access through Win32::API::Prototype as follows:
Update: Changed use to require + import.
#! perl -slw use strict; use Fcntl qw[ :flock ]; $|=1; if( $^O eq 'MSWin32' ) { { local $^W; require Win32::API::Prototype; Win32::API::Prototype->import( 'ApiLink' ); } ApiLink( 'perl58', 'int win32_flock(int fd, int oper)' ) or die $^ +E; our $flock; *flock = *win32_flock = *win32_flock; } die 'Already running' unless flock( DATA, LOCK_EX ); sleep 10; flock( DATA, LOCK_UN ) or die $!; __DATA__ stuff
However, in my tests just now, when running a second copy of the above script, the call to flock( LOCK_EX ), causes the script to silently terminate, so that may not be so useful after all.
I'm not sure whether
- I'm simply using the call incorrectly (which is possible as I've never needed flock());
- or if there is a bug in the implementation (at win32.c line 2246 in the 5.8.8 sources);
- Or there is a bug in the transition between perl and C via Win32::API(::Prototype);
but maybe this and the pointer to the source will let someone who knows what they are doing work out which and, either point out my stupidity or raise a bug against the responsible component?
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom