Comment by wmf
4 months ago
You need to sync twice because Unix is dumb: "According to the standard specification (e.g., POSIX.1-2001), sync() schedules the writes, but may return before the actual writing is done." https://man7.org/linux/man-pages/man2/sync.2.html
Then how do you know the writes are done after the second sync?
AFAIK multiple syncs can't happen at the same time so the second sync implicitly waits for the first one to complete.
If it was that simple, then why doesn't sync just do 2x sync internally?
2 replies →
> Unix is dumb
I don't know. Now async I/O is all the rage and that is the same idea.
If they had a sync() system call and a wait_for_sync_to_finish() system call then you'd be right. But they didn't have those.
https://news.ycombinator.com/item?id=46268127 (To quote yourself :-) )
The syscall is literally called "sync", though.
I think it is a way of the OS to shoehorn async into a synchronously written application.