Well I tried my code on Linux and the failure case looks a little different:
$ ./locktest & sleep 4; ./locktest
[1] 1553
Using flock()...
1553 shares.
1553 owns
1553 shares
Using flock()...
1557 shares.
1557 waiting for previous instance(s) to exit...
1553 owns
1557 owns
Running...
1557 owns
1553 can't revert self lock to shared: Resource temporarily unavailabl
+e
1557 shares
^C
[1]+ Exit 11 ./locktest
Which demonstrates that Linux doesn't have the strong preference for non-blocking requests like FreeBSD appears to have.
Having lock up-/down-grading introduce a race condition where the lock is freed first is such a horrid design choice to my mind that I didn't even consider the possibility when reading "man flock" (this is not even mentioned in Linux's extremely short version of "man flock" tho my test cases show that it is the case there as well).
Thanks for the enlightenment. Now I have one more reason to hate flock. I should find a module that provides a convenient wrapper for fcntl locks... (:
- tye (but my friends call me "Tye")
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|