<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Feb 27, 2014, at 3:23 AM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Thu, Feb 27, 2014 at 12:50 AM, Vikas Bhargava<br><<a href="mailto:vikasbhargava@gmail.com">vikasbhargava@gmail.com</a>> wrote:<br><blockquote type="cite">Hi,<br>I am using clang::ToolInvocation class to compile some code in-memory:<br><br> clang::tooling::ToolInvocation ti<br> (<br> compilerArgs,<br> new clang::EmitBCAction(),<br> new clang::FileManager(clang::FileSystemOptions())<br> );<br> //filename is the name of the source file, e.g. "Somefile.cpp"<br> //sourcecode contains the source of the file<br> ti.mapVirtualFile( filename, sourcecode );<br> bool ret = ti.run();<br><br>In order to speed up compilation of several sources, I call the above code<br>concurrently in separate threads, with each thread compiling its own source<br>code. However, this does not work because clang::CompilerInstance calls<br>llvm::Sys::RemoveFileOnSignal which in turn calls RegisterHandlers() which<br>is not re-entrant.<br><br>Is there a way to make RegisterHandlers() re-entrant? I do call<br>llvm::start_multi_threaded() before any of this, hoping that it will make<br>llvm routines thread-safe, but to no avail.<br></blockquote><br>Seems like it is a bug in either RemoveFileOnSignal(). For some<br>reason, the first one releases the mutex before calling the<br>RegisterHandlers().<br><br>bool llvm::sys::RemoveFileOnSignal(StringRef Filename,<br> std::string* ErrMsg) {<br> SignalsMutex.acquire();<br>...<br> SignalsMutex.release();<br><br> RegisterHandlers();<br> return false;<br>}<br><br>CC'ing Argyrios because this is important for libclang.<br><br>Argyrios: what do you think -- should we call RegisterHandlers() under a mutex?<br></div></blockquote><div><br></div><div>That, or get RegisterHandlers to use the mutex.</div><div>Also access to CallBacksToRun is not thread-safe (the whole file probably needs reviewing..)</div><div><br></div><div>But it's not so clear to me what is the exact symptom, is there a crash occurring ? Vika, could you explain ?</div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>Dmitri<br><br>--<span class="Apple-converted-space"> </span><br>main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/</div></blockquote></div><br></body></html>