[LLVMdev] JITted code in multiple threads

Chris Lattner sabre at nondot.org
Sat Mar 1 01:14:43 PST 2008

On Feb 27, 2008, at 1:10 AM, Aaron Dwyer wrote:

> I just thought of something that scared me, and I'm hoping there is a
> happy ending.  I realized recently that the JITter does not
> necessarily finish JITting inside of getPointerToFunction.  Instead,
> it often generates stubs which get a final JIT only upon jumping to
> them.  Now--I am in the situation where I'd like to do a
> getPointerToFunction, and then take the pointer and pass it out to
> multiple cores to execute the code I've generated in parallel.  This
> seems like a problem--if jumping to an address means code will be
> munged, then two or more cores trying to jump to that address at the
> same time might all try to JIT the stubs, resulting in a barrage of
> random code!!
> This seems like a very obvious issue, so I'm guessing there is a
> simple answer for this.  What are peoples' thoughts?  Any and all are
> appreciated.

The JIT is thread safe: it uses a pthread mutex to prevent multiple  
threads from clobbering each other, even if lazy compilation is  


More information about the llvm-dev mailing list