What you're describing is a "race condition".
I know that on Windows you can open a file in "exclusive mode" so that no other process can read or write the file by setting dwShareMode to 0 in the call to CreateFile(). (It allows finer granularity than that, but that is the safest setting in this context.) If all applications are required to do this any time they read or write the file, and are also required to retry opening the file for (say) one second if an open attempt fails, then the race condition goes away.
I know that on Windows you can open a file in "exclusive mode" so that no other process can read or write the file by setting dwShareMode to 0 in the call to CreateFile(). (It allows finer granularity than that, but that is the safest setting in this context.) If all applications are required to do this any time they read or write the file, and are also required to retry opening the file for (say) one second if an open attempt fails, then the race condition goes away.