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

vikasbhargava vikasbhargava at gmail.com
Fri Feb 28 09:40:52 PST 2014


The fix in llvm seems straightforward. llvm::sys::RemoveFileOnSignal
releases a mutex too soon. It should hold it till RegisterHandlers()
returns. I will try this out and see if it fixes this issue (and doesn't
break anything else).

thx
Vikas.
=======


On Fri, Feb 28, 2014 at 1:53 AM, Manuel Klimek [via Clang Developers] <
ml-node+s42468n4038165h73 at n3.nabble.com> wrote:

> On Thu, Feb 27, 2014 at 2:07 AM, vikasbhargava <[hidden email]<http://user/SendEmail.jtp?type=node&node=4038165&i=0>
> > 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
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=4038165&i=1>
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=4038165&i=2>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://clang-developers.42468.n3.nabble.com/multithreaded-use-of-clang-tooling-ToolInvocation-tp4038119p4038165.html
>  To unsubscribe from multithreaded use of clang::tooling::ToolInvocation, click
> here<http://clang-developers.42468.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4038119&code=dmlrYXNiaGFyZ2F2YUBnbWFpbC5jb218NDAzODExOXwtNTUwNDUyODkx>
> .
> NAML<http://clang-developers.42468.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




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



More information about the cfe-dev mailing list