2 ms·
How do you know the OS/hardware will perform the writes in the order that your program performs them?
by amelius 8y ago
How do you know the OS/hardware will perform the writes in the order that your program performs them?
- boomlinde 8y agoWithout disabling any (potentially and probably out-of-order) disk cache or using some kind of barrier, this will just not provide any guarantees in exceptional error conditions like power failure, crashes etc. Maybe it's better understood as being "atomic" only on the stream level, in the sense that you can kill the userland process at any time and always end with a working file. Even then, as some other user already mentioned, something like fwrite of four bytes for the TOC offset isn't atomic.
- pjc50 8y agoThe normal solution is to sync between each write, although (Postgres passim) this may not behave as you expect either.