<p>I would also recommend you look for examples of having multiple readers and only 1 writer in a critical section heres a short paper with a good solution <a href="http://arxiv.org/PS_cache/cs/pdf/0303/0303005v1.pdf" rel="nofollow noreferrer">http://arxiv.org/PS_cache/cs/pdf/0303/0303005v1.pdf</a></p>

<p>Alternatively you could look at creating copies of the file each time it is requested and when it comes time to write any changes to the file you merge with the original file.</p>
Concurrent file write
<p>how to write to a text file that can be accessed by multiple sources (possibly in a concurrent way) ensuring that no write operation gets lost?</p>

<p>Like, if two different processes are writing in the same moment to the file, this can lead to problems. The simples solution (not very fast and not very elegant) would be locking the file while beginning the process (create a .lock file or similar) and release it (delete the lock) while the writing is done.</p>

<p>When beginning to write, i would check if the .lock file exists and delay the writing till the file is released.</p>

<p>What is the recommended pattern to follow for this kind of situation?</p>

<p>Thanks</p>

<p><strong>EDIT</strong>
I mean processes, like different programs from different clients, different users and so on, not threads within the same program</p>