file locking

Discussion in 'Ruby' started by Mark Volkmann, Jan 22, 2006.

  1. 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.

    --
    R. Mark Volkmann
    Partner, Object Computing, Inc.
     
    Mark Volkmann, Jan 22, 2006
    #1
    1. Advertising

  2. Mark Volkmann wrote:
    > 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Eero Saynatkari, Jan 22, 2006
    #2
    1. Advertising

  3. Mark Volkmann

    Jeremy Henty Guest

    On 2006-01-22, Mark Volkmann <> wrote:

    > 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
     
    Jeremy Henty, Jan 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Praveen
    Replies:
    1
    Views:
    752
    Kevin Yu [MSFT]
    Apr 16, 2005
  2. Timasmith
    Replies:
    4
    Views:
    471
    Bjorn Borud
    Nov 1, 2006
  3. Praveen
    Replies:
    5
    Views:
    181
    Kevin Yu [MSFT]
    Apr 20, 2005
  4. Ludwigi Beethoven
    Replies:
    5
    Views:
    333
    Mike Hall
    Jul 26, 2003
  5. sonet
    Replies:
    9
    Views:
    134
Loading...

Share This Page