[PATCH] D81525: [Support] Initialize outs() errs() nulls() once

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 01:36:09 PDT 2020


sammccall added a comment.

There's a second threadsafety issue I'd like to highlight, around runtime rather than initialization.

raw_ostreams are not threadsafe, including outs(). It's not necessarily safe to flush outs when errs() is accessed.
For example, in clangd errs() is the log stream, written by multiple threads with a lock. outs() is the protocol stream, written by the main thread without a lock.
After this change, all logging threads are trying to flush outs, racing with the main thread which is writing to it.
I can fix this in clangd but it has me questioning whether this is unsafe for other existing users and likely to go unnoticed for new ones.

Is it really vital that this behaviour be the default? I mentioned on D81156 <https://reviews.llvm.org/D81156> that this seemed surprising and unsafe.
std::{cout,cerr} do something vaguely related (they're threadsafe and synchronize between operations), but that seems a) much safer than this and b) mostly a concession to history maybe?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81525/new/

https://reviews.llvm.org/D81525





More information about the llvm-commits mailing list