[LLVMdev] LLVM and multi-threading

Nick Lewycky nicholas at mxc.ca
Thu Jul 19 01:54:06 PDT 2012


Mario Schwalbe wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> I know similar questions have been asked several times, but I couldn't
> find an answer in earlier threads.
>
> Is it safe to process several modules concurrently in different threads
> if they share the same LLVM context instance, i.e., is the context
> implementation thread-safe?

Nope, you need one context per thread in the general case.

Whether the context implementation itself is thread-safe is a separate 
issue (it isn't, but even if it were that wouldn't be enough). The issue 
is the LLVMContext-owned objects (non-GV Constant and Type) which have 
global state (eg. use lists) which aren't protected by locks.

Nick



More information about the llvm-dev mailing list