|No such thing as a small change|
Re^3: Thread safe equivalent of LINUX touch commandby BrowserUk (Pope)
|on Nov 22, 2012 at 19:17 UTC||Need Help??|
I guess I think of "?-save" as that you don't allow a race condition to exist, and must use locking to prevent the race condition.
In order for the potential for a "race condition" to exist, several algorithmic prerequisites are needed:
These algorithmic prerequisites are required because:
As (the normal meaning of) 'touching a file' does not require any of these, a "race condition" cannot occur.
That said, it is possible to contrive a bespoke "touch" requirement that could introduce a race condition. For example, an algorithm might require that not just the 'modified' timestamp be set; but also, one, the other, or both of the other two timestamps be set to the same value.
In the case, if the OS, or the tool, required multiple calls to set multiple timestamps, it would be possible for one thread to modify one of the TSs, then get swapped out; then a second thread modifies all of the affected TSs; and then the first thread gets another timeslice and modifies the other one or two TSs.
The result would be that the file would get a mismatched set of timestamps.
The windows SetFileTime system call (can) set all three in one call, thus preventing that possibility, but that does not prevent a particular implementation of 'touch' from choosing to call the function multiple times to set multiple timestamps, in which case a race condition would be introduced.
And I don't know if other OSs can update multiple timestamps as an atomic operation or not.
Hence, to really answer the OPs question, it will be necessary for him to answer my question and clarify exactly what he is doing with his 'touch' operation.
The values they write need to be derived from a value previously read from (the same or different) shared storage.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.