file locking

M

Mark Volkmann

I'm trying to understand usage of file.flock(File::LOCK_SH) which
obtains a shared lock. The documentation says it allows other
processes to also obtain a shared lock. What's the point of a lock if
it isn't locking anybody else out? There must be a use case for this
that I'm not seeing.

Also, the documentation for File.flock says that it isn't supported on
all platforms. If you know of platforms that definitely do or do not
support this, I'd like to hear about them. I'm particularly interested
in XP and Fedora Core Linux.
 
E

Eero Saynatkari

Mark said:
I'm trying to understand usage of file.flock(File::LOCK_SH) which
obtains a shared lock. The documentation says it allows other
processes to also obtain a shared lock. What's the point of a lock if
it isn't locking anybody else out? There must be a use case for this
that I'm not seeing.

A shared lock is usually implemented as a read-lock; in
other words, multiple processes can read from the file
at the same time but none may modify it.
Also, the documentation for File.flock says that it isn't supported on
all platforms. If you know of platforms that definitely do or do not
support this, I'd like to hear about them. I'm particularly interested
in XP and Fedora Core Linux.

This I do not know.


E
 
J

Jeremy Henty

I'm trying to understand usage of file.flock(File::LOCK_SH)
... What's the point of a lock if it isn't locking anybody else out?

A shared lock locks out anyone who wants an exclusive lock. Typically
you want an exclusive lock for writing to a file and a shared lock for
reading it. That's because it's OK for several people to read a file
simultaneously, but if someone wants to write to it then no-one else
should be allowed to read *or* write, otherwise hilarity may ensue.

Cheers,

Jeremy Henty
 

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

Similar Threads

Is this file locked? 0
ASP requests and locking 4
file locking... 4
File locking 3
file locking 1
More file locking problems 4
DB_File and File Locking -- Best Practices 8
Correct file locking techniques 4

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top