Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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


Dave

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. :)


      Dave

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-11-25 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?