Is a successful call to write(2) atomic?
Ronald F. Guilmette
rfg at tristatelogic.com
Wed Jun 16 07:39:29 UTC 2021
In message <20210616072633.e4bd29839249465e385bbf6f at sohara.org>,
Steve O'Hara-Smith <steve at sohara.org> wrote:
> IOW if one process writes ABC and another writes DEF both at the
>end of file you might get ABCDEF but you won't get ABDCEF you might also get
>ABDEF as D overwrites C...
Yup. Some of the "garbled" lines I have been getting look suspiciously
like the "ABDEF" in your example.
> John's code will work (it is the standard solution) - provided
>*every* writer uses it - without the O_APPEND you would need to put a seek
>to EOF inside the locked section which is the pattern I most often wind up
So the O_APPEND by itself isn't enough to fix the problem? I still have
to wrap the calls to write() inside some sort of locking code?
I'll try both... O_APPEND, with and without locking... but it kind of seems
to me that if O_APPEND, by itself, were actually doing what the man page
says it does, then that alone ought to be enough to prevent garbling of
the output lines.
More information about the freebsd-questions