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

Manuel Klimek klimek at google.com
Fri Feb 28 01:48:36 PST 2014


On Thu, Feb 27, 2014 at 2:07 AM, vikasbhargava <vikasbhargava at gmail.com>wrote:

> 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?
>

All of this is currently not thread-safe. We usually use multiprocessing to
solve the problem. Patches to help making it thread-compatible would be
welcome :)


>
> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140228/0d495942/attachment.html>


More information about the cfe-dev mailing list