in reply to File reade and recreate
You may also want to research how to lock the file from read through write. If multiple processes have the opportunity of simultaneous execution, you have a race condition where you can get anything from the correct behavior to missing one of the updates, to corrupting the data in the file.
In this case I don't think you have the possibility of corruption (that scenario can happen more easily on files with larger datasets), but you may miss one of the updates. ProcA starts and reads the counter. ProcB gets control, reads the counter (same value), increments, and writes the counter. ProcA now resumes, increments the (now outdated) counter, and writes it. Your counter is now one less than it should be.
--MidLifeXis
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File reade and recreate
by adriang (Sexton) on Aug 21, 2014 at 07:53 UTC |