LLVM and multi-threading

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?

Thanks and ciao,
Mario

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

Hi Mario,

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?

no, different threads should use different contexts, not share the same
context.

Ciao, Duncan.