<div dir="ltr">The other solution would be to use ninja instead of make if you can. Ninja always buffers command output so that error messages from a parallel build don't interleave. <a href="https://ninja-build.org/manual.html#_comparison_to_make">https://ninja-build.org/manual.html#_comparison_to_make</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 6, 2019 at 4:02 PM Tim Northover via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Jie,<br>
<br>
<br>
On Sat, 6 Apr 2019 at 01:43, Jie Zhou via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> In a pass I’m using raw_fd_ostream to write a string to a file. Does raw_fd_ostream guarantee<br>
> the write is atomic when I do parallel compilation (currently I’m using -j8)?<br>
<br>
raw_fd_ostream doesn't really attempt to solve this problem. All<br>
writes get filtered through the write_impl function which calls POSIX<br>
::write in chunks (large ones -- 1GB). Additionally, individual calls<br>
to << operators may or may not be buffered, and if they are it's with<br>
a fixed size buffer rather than a transaction based system.<br>
<br>
According to <a href="https://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix</a>,<br>
those individual calls to ::write are atomic and won't interfere<br>
provided the file has been opened in append mode. So your goal should<br>
be to ensure that each logging event gets implemented as a single call<br>
to ::write.<br>
<br>
The most straightforward way would obviously be to do it yourself. In<br>
LLVM you might do your normal writing to a raw_string_ostream and then<br>
call ::write once on that.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>