<div dir="ltr">Hi,<div><div>I am using clang::ToolInvocation class to compile some code in-memory:</div><div><br></div><div><span style="font-family:'courier new',monospace;font-size:x-small">   clang::tooling::ToolInvocation ti</span><br>
</div><div><div><font face="courier new, monospace" size="1">      (</font></div><div><font face="courier new, monospace" size="1">       compilerArgs,</font></div><div><font face="courier new, monospace" size="1">       new clang::EmitBCAction(),</font></div>
<div><font face="courier new, monospace" size="1">       new clang::FileManager(clang::FileSystemOptions())</font></div><div><font face="courier new, monospace" size="1">      );</font></div><div><font face="courier new, monospace" size="1">   //filename is the name of the source file, e.g. "Somefile.cpp"</font></div>
<div><font face="courier new, monospace" size="1">   //sourcecode contains the source of the file</font></div><div><font face="courier new, monospace" size="1">   ti.mapVirtualFile</font><span style="font-family:'courier new',monospace;font-size:x-small">( filename, sourcecode );</span></div>
</div><div><span style="font-family:'courier new',monospace;font-size:x-small">   bool ret = ti.run();</span></div><div><span style="font-family:'courier new',monospace;font-size:x-small"><br></span></div>
<div><font face="arial, helvetica, sans-serif">In order to speed up compilation of several sources, I call the above code concurrently in separate threads, with each thread compiling its own source code. However, this does not work because clang::CompilerInstance calls llvm::Sys::RemoveFileOnSignal which in turn calls RegisterHandlers() which is not re-entrant.</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Is there a way to make RegisterHandlers() re-entrant? I do call llvm::start_multi_threaded() before any of this, hoping that it will make llvm routines thread-safe, but to no avail. </font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Also, is there any other way of doing parallel compilation?</font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">thx</font></div><div><font face="arial, helvetica, sans-serif">Vikas.</font></div><div><font face="arial, helvetica, sans-serif">=========</font></div></div></div>