<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:19.33333396911621px">Yes, there is a crash when lot of threads are used. I am using 60 threads to compile 60 source files and the crash happens 90% of the time. Here is the relevant stack trace:</span><div style="font-family:arial,sans-serif;font-size:19.33333396911621px">
<br></div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px"><div>(gdb) bt</div><div>#0 0x00007f30e11d9e4e in __libc_sigaction (sig=31, act=<optimized out>, oact=0x2c5ffa0)</div><div> at ../sysdeps/unix/sysv/linux/x86_64/sigaction.c:71</div>
<div>#1 0x0000000001c75636 in RegisterHandlers() ()</div><div>#2 0x0000000001c7579f in llvm::sys::RemoveFileOnSignal(llvm::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) ()</div>
<div>#3 0x0000000000ed3286 in clang::CompilerInstance::createOutputFile(llvm::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, bool, bool, llvm::StringRef, llvm::StringRef, bool, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) ()</div>
<div>#4 0x0000000000ed20c8 in clang::CompilerInstance::createOutputFile(llvm::StringRef, bool, bool, llvm::StringRef, llvm::StringRef, bool, bool) ()</div><div>#5 0x0000000000ed200b in clang::CompilerInstance::createDefaultOutputFile(bool, llvm::StringRef, llvm::StringRef) ()</div>
<div>#6 0x0000000000d166b9 in clang::CodeGenAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef) ()</div><div>#7 0x0000000000ef87a4 in clang::FrontendAction::CreateWrappedASTConsumer(clang::CompilerInstance&, llvm::StringRef) ()</div>
<div>#8 0x0000000000ef943e in clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) ()</div><div>#9 0x0000000000ed3e01 in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) ()</div>
<div>#10 0x000000000140dad9 in clang::tooling::FrontendActionFactory::runInvocation(clang::CompilerInvocation*, clang::FileManager*, clang::DiagnosticConsumer*) ()</div><div>#11 0x000000000140d423 in clang::tooling::ToolInvocation::run() ()</div>
</div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px"><br></div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px"><br></div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px">
Please let me know if you want me to create a working project to illustrate the crash.</div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px"><br></div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px">
thx</div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px">Vikas.</div><div style="font-family:arial,sans-serif;font-size:19.33333396911621px">=========</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Feb 27, 2014 at 7:31 AM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:kyrtzidis@apple.com" target="_blank">kyrtzidis@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><br><div><div><div class="h5"><div>On Feb 27, 2014, at 3:23 AM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>> wrote:</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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Thu, Feb 27, 2014 at 12:50 AM, Vikas Bhargava<br>
<<a href="mailto:vikasbhargava@gmail.com" target="_blank">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></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>
<div class=""><br><blockquote type="cite"><div style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br>Dmitri<br><br>--<span> </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" target="_blank">gribozavr@gmail.com</a>>*/</div>
</blockquote></div></div><br></div></blockquote></div><br></div>