Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Strange IO + concurrency issue

by RichardK (Priest)
on Sep 28, 2013 at 16:44 UTC ( #1056151=note: print w/ replies, xml ) Need Help??


in reply to [SOLVED] Strange IO + concurrency issue

I'm not entirely sure what you are trying to achieve, but the issue seems to be that you are only locking the file open not the file writes.

so :- fork 1 fork 2 takes the lock opens file1 releases the lock starts writing data gets pre-empted takes the lock opens file1 (& deletes contents) releases the lock starts writing data Etc....

So potentially many children all writing to the same file at the same time. If you get each fork to write a different character to the file you'll see what's happening.

It's usually better to get each child to write to its own temp file, File::Temp, then rename it.


Comment on Re: Strange IO + concurrency issue
Download Code
Re^2: Strange IO + concurrency issue
by vsespb (Hermit) on Sep 28, 2013 at 17:16 UTC
    So potentially many children all writing to the same file at the same time.
    See above Re^2: Strange IO + concurrency issue - write-to file is actually protected (although it's extremely unclear in code). What was not protected is file copy (where destination file is unique)
    It's usually better to get each child to write to its own temp file
    Same, in this case there are no concurrent writes to same file (even copy writes to unique file).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-08-28 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls