At 06:01 PM 5/14/01 -0400, Jeff Pinyan wrote:
>On May 14, Brian Shoemaker said:
>
> >The Perl 5 book I have says flock function doesn't work in Windows systems.
> >
> >I don't want to create a lock file each time someone accesses a file and
> >then have to delete that lock.
>
>A rather clever way to emulate locking is to use mkdir() and rmdir().
Ooh, that is clever. Has it been encapsulated in a CPAN module?
>Although it requires you to create a lock file, it's atomic and safe.
>
> sub lock {
> 1 until mkdir "$_[0].lck", 0777;
Perhaps sleep 1 until mkdir would be a little less stressful on the average
system :-)
> $locked{$_[0]}++;
> }
>
> sub unlock {
> rmdir "$_[0].lck";
> delete $locked{$_[0]};
> }
>
> END {
> rmdir "$_.lck" for keys %locked;
> }
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com