Win 2K3 & File Locking

B

Ben Liddicott

As far as I know, only those which exist in Perl/Win32 anyway. Check the docs.

The main biggie is twofold.

1. Locks on windows are mandatory.
2. Perl flock locks don't play nicely with other win32 applications.

Windows has two kinds of mandatory locks, and no advisory locks. Share mode, which is applied at the time you open the file, and range locks, which are applied to an open file. Most applications open files with FILE_SHARE_READ|FILE_SHARE_WRITE, meaning that the file can be opened by another process with read or write access. Applications which need to lock a file generally deny sharing, which means that other applications will fail to open them. Conversely, many applications assume that if they can open the file, they will be able to read it. When they successfully open the file but fail to read any data, they will have a sort of "don't know why" error, and it will be treated differently from if they failed to open the file.

In unix, file locks are applied after the file is opened. In order to allow this to happen in Perl on Win32, perl's flock sets a range lock when you call flock. This allows interoperation with other perl modules, but will surprise most applications, which expect that if the file is in use, the open will fail.

I'm working on a portable locking implementation which provides share-mode opening on windows, and equivalent semantics on Unix/Linux. It also provides portable range locks on Solaris, BSD, Linux and Win32.

Not done yet though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top