<div dir="auto">llvm::execute_on_thread waits for completion of the operation, clangd spawns long-living threads managing requests to the AST and short-lived threads for async processing of requests.<div dir="auto"><br><div dir="auto">Both are asynchronous and we only join them when clangd exits.</div><div dir="auto">We might have something similar to llvm:: execute_on_thread, but that would mean reimplementing a big chunk of threading lib from STL, I think it's exactly what Dmitry proposed as an option.</div></div></div><br><div class="gmail_quote"><div dir="ltr">Alex Lorenz <<a href="mailto:aleksei_lorenz@apple.com" target="_blank" rel="noreferrer">aleksei_lorenz@apple.com</a>> schrieb am Fr., 17. Aug. 2018, 20:05:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I think the best solution is to use `llvm::llvm_execute_on_thread` instead of `std::thread`.<div><br></div><div>Cheers,</div><div>Alex<br><div><br><blockquote type="cite"><div>On Aug 17, 2018, at 7:12 AM, Roman Popov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="m_-5224842788283449953m_7995900156502890709Apple-interchange-newline"><div><div dir="ltr">In case MacOS LibC++ is implemented on top of pthreads, than you can can use pthreads API to set default stack size. This will probably be miminal possible platform-specific workaround.<br></div><br><div class="gmail_quote"><div dir="ltr">пт, 17 авг. 2018 г. в 6:27, Ilya Biryukov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Would be nice to get around this limitation in the standard library. I don't think we can do it in a standard-compliant way, though.<div>There's `llvm::llvm_execute_on_thread`, but it is an OS-specific implementation.</div><div><br></div><div>Are there any ways to set default stack sizes for the newly created threads? Even if it's platform-specific code, it should be pretty localized and we could reuse the STL implementation of threads.</div><div>I don't know of reliable APIs to do that, unfortunately.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 17, 2018 at 2:43 PM Eric Liu <<a href="mailto:ioeric@google.com" rel="noreferrer noreferrer" target="_blank">ioeric@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><a class="m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871gW m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871GWVZpf" id="m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871IloFPc-2" href="mailto:clangd-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">+clangd-dev@lists.llvm.org</a> <a class="m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871gW m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871GWVZpf" id="m_-5224842788283449953m_7995900156502890709m_-3112114708591987290m_6659629032532660871IloFPc-3" href="mailto:ibiryukov@google.com" rel="noreferrer noreferrer" target="_blank">+Ilya Biryukov</a> <br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 17, 2018 at 2:41 PM <a href="mailto:Dmitry.Kozhevnikov@jetbrains.com" rel="noreferrer noreferrer" target="_blank">Dmitry.Kozhevnikov@jetbrains.com</a> via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<br>
clangd uses std::thread for spawning worker threads to parse files (see AsyncTaskRunner::runAsync in tools/clang/tools/extra/clangd/Threading.cpp). Unfortunately, std::thread lacks the ability to customize the stack size, and the default one might be insufficient for parsing complex source files. For example, on macOS, the default stack size for non-main threads is 512K, so the following code causes a stack overflow (on my machine) with clangd, while being way below the default constexpr evaluation depth threshold:<br>
<br>
constexpr int foo(int x) {<br>
return x == 1 ? 1 : foo(x - 1) + 1;<br>
}<br>
static_assert(foo(50) > 0, "");<br>
<br>
This also can be observed on some real-world projects.<br>
<br>
Do I understand correctly that the only way to fix it would be to abandon std::thread and reimplement the platform-specific thread spawning (using pthreads/WinAPI), or is there another solution available in LLVM/clang codebase?<br>
<br>
Best regards,<br>
Dmitry Kozhevnikov._______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-5224842788283449953m_7995900156502890709m_-3112114708591987290gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" rel="noreferrer noreferrer" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></div></div></blockquote></div>