if llvm can translate and generate the function in parallel with multithread

We try to use llvm to translate and generate the native code in
parallel with multi-thread. But some various
bugs will be triggered. We run the following code in multithread environment:

Modifying modules, function, blocks, etc. is not thread safe within the same context. In your example code, is the context different in each thread? Also calls to getPointerToFunction are thread safe in some cases, but not in others. see this: http://llvm.org/docs/ProgrammersManual.html#threading

In my own multithreaded JIT, I always hold a lock on the ExecutionEngine when performing code transformation. For example,

FunctionPassManager PM(F->getParent());
MutexGuard locked(cg->lock);

where cg is a singleton ExecutionEngine instance that I use throughout my code. Unfortunately this serializes access to all of my transformation passes, but at least it’s safe.