[cfe-dev] multithreaded use of clang::tooling::ToolInvocation

vikasbhargava vikasbhargava at gmail.com
Wed Feb 26 17:07:24 PST 2014


Hi,
I am using clang::ToolInvocation class to compile some code in-memory:

   clang::tooling::ToolInvocation ti
      (
       compilerArgs,
       new clang::EmitBCAction(),
       new clang::FileManager(clang::FileSystemOptions())
      );
   //filename is the name of the source file, e.g. "Somefile.cpp"
   //sourcecode contains the source of the file
   ti.mapVirtualFile( filename, sourcecode );
   bool ret = ti.run();

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.

Is there a way of making this parallel compilation work? I do call
llvm::start_multi_threaded() before any of this, hoping that it will make
llvm routines thread-safe, but to no avail. Are there any other classes that
do not set llvm::Sys::RemoveFileOnSignal to true?

thx
Vikas.
=========



--
View this message in context: http://clang-developers.42468.n3.nabble.com/multithreaded-use-of-clang-tooling-ToolInvocation-tp4038119.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list