[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Best way to check file modification time?
From: |
Stefan Monnier |
Subject: |
Re: Best way to check file modification time? |
Date: |
Tue, 17 Nov 2015 12:12:45 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
>> I can easily move the mod time checking to a position in the code that's
>> closer to the actual reading or saving of the file, but I suspect that
>> only reduces the problem, it doesn't eliminate it altogether. So I'm
>> wondering if there's a Right Way Ѣ to do this. If not, any advice on how
>> to reduce the risks as much as possible would be great!
You can't solve this without locking.
The mod-time check has to be done before writing (since writing is
conditional on the result of the mod-time check), you have a race:
User A checks mod-time
User B checks mod-time
User A writes
User B writes
And this applies no matter how/when the mod-time was originally acquired.
Stefan