1. 3

  2. 2

    Mandatory locking… Seriously, don’t do it. Advisory locks are the only thing that makes any sense…Still not convinced?… Look, imagine someone is holding a mandatory lock on a file, so you try to read() from it and get blocked. Then he releases his lock, and your read() finishes, but some other guy reacquires the lock. You fiddle with your block, modify it, and try to write() it back, but you get held up for a bit, because the guy holding the lock isn’t done yet. He does his own write() to that section of the file, and releases his lock, so your write() promptly resumes and overwrites what he just did.

    How is this problem unique to mandatory file locking? This is the quintessential race condition example. You’re aware that this could happen, so you take an exclusive mandatory lock on the file, do your read, do your write, then release the lock. How is the situation any better for advisory locks? If you’re going to be releasing your advisory lock between the read and the write, how is that not going to result in lost writes?

    And then he says, still on the topic of mandatory file locks,

    What good does that do anyone? Come on. If you want locking to do you any good whatsoever, you’re just going to have to acquire and release your own locks.

    How does mandatory locking equate to “not acquiring and releasing one’s own locks”, but advisory locking somehow does?

    I must be missing something obvious here…