Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I agree with everything Aristotle said, I just wanted to point something out that may not be obvious.

Where it says "If you want to write to a file, do"...

Make sure you do NOT open the file with a single >, or in truncate mode.

The lock is, as explained in the docs, only an advisory lock, which means if some code does not check the lock there are no restrictions on it going in and messing with the file.

So while a good citizen your code locks a file and is doing some reading, a bad citizen could open, truncate, the file if they never check the lock, and your code will be out of luck.

And not mentioned is locking multiple files, a common mistake is made in the order you lock files. The rule is, all code should lock resources in the same order. And when you release locks you should do in the inverse order. If you have some code that locks A, B, C, and other code that locks C, A you are going to eventually hit deadlock.

Can you tell I made some mistakes in the past ;-)

Hope this helps!

In reply to Re: Re: Proper use of flock by Helter
in thread Proper use of flock by stupidius

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2023-03-23 18:08 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.