in reply to Re: Strange IO + concurrency issue
in thread [SOLVED] Strange IO + concurrency issue
1. You are opening a lock to a semaphore file (lock.tmp).I knew that if lock extended to other steps it works, but I could not understand why.
2. Once that lock is obtained you are opening an output file (somefile$_.tmp).
3. You unlock/close your semaphore file.
4. You write to somefile$_.tmp
5. You close somefile$_.tmp.
6. You copy from your tmp file to a new file.
Steps 4, 5, and 6 are unprotected.
The thing is: When I open file on step (2), I write to it in step (4). But steps (4) and (5) are actually protected. Steps (4) and (5) is performed only if that process was the one who created file. Otherwise step is skipped. (and this was intentional - I was trying to minimize lock time which was important)
Notice "if ($f)"
Problem was that step (6) unprotected. And this assertion was wrong:if ($f) { print ($f "x") for (1..40_000_000); close $f; }
die if -s $filename != -s $newfilename;Correct assertion would be:
die if 40_000_000 != -s $newfilename;i.e. when data copied, file could be in the middle of creation by another process. so in the end I see:
correct size of $filename
wrong size of $newfilename
assertion passed: if -s $filename != -s $newfilename;
Thank you! I'll mark post as SOLVED
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Strange IO + concurrency issue
by ig (Vicar) on Sep 30, 2013 at 05:50 UTC | |
by vsespb (Chaplain) on Sep 30, 2013 at 08:28 UTC |
In Section
Seekers of Perl Wisdom