Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Temporary usage of RAM memory

by davido (Cardinal)
on Apr 11, 2014 at 00:46 UTC ( #1081896=note: print w/replies, xml ) Need Help??

in reply to Re: Temporary usage of RAM memory
in thread Temporary usage of RAM memory

rename is atomic, but readdir followed by rename isn't. So if the goal is to increment a number encoded into a filename, one has to read the directory to find the file's number, and then rename it. If there's the possibility of two or more invocations of the script working in close time-proximity there's a race condition, and I don't see how the rename approach can eliminate the need for some type of flocking.

It's possible you've thought this through, and I'm missing something simple. If so, I'm open to learning the new trick. ;)

(Or maybe I'm reading too much into your suggestion.)


Replies are listed 'Best First'.
Re^3: Temporary usage of RAM memory
by fullermd (Priest) on Apr 11, 2014 at 05:16 UTC

    Only one of the racing processes can win the rename, so you have to check it for failure and re-try the readdir/rename loop. So you don't need locking, but you do need checking and retrying.

      Thanks, that makes sense. :)


Re^3: Temporary usage of RAM memory
by thanos1983 (Parson) on Apr 11, 2014 at 08:47 UTC

    To: Dave

    Thank you for your time and effort, I was not even aware of all these capabilities of perl. I am new into programming so I only know the basics. It is interesting to know and apply new ideas.

    Again thank you for your time and effort, It is nice to learn something new everyday.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1081896]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-10-26 09:54 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.