<div dir="ltr">Rafael, I tried a few stories you suggested.<div><br></div><div>1) Launch noop(return nullptr) and detach it in main context</div><div>I saw crash in pthread_detach.</div><div><br></div><div>2) Avoid grandchildren. Just launch threads in main context.</div><div>I couldn't happen crash in a million run.</div><div>Note, it's a devil's proof.</div><div><br></div><div>I haven't tried cond var, since I think it doesn't make sense.</div><div><br></div><div>(2) might be ideal but I am worried it would increase latency to set up threads.</div><div>I think we may use naked pthread_create(<span style="color:rgb(33,33,33)">PTHREAD_CREATE_DETACHED) there, instead of std::thread.</span></div><div><span style="color:rgb(33,33,33)"><br></span></div><div><span style="color:rgb(33,33,33)">I wish we didn't meet the processor's errata. It ought to be impossible.</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Nov 4, 2017 at 6:50 AM Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">And an even simpler thing to try: start all the threads from the main<br>
thread.<br>
<br>
I think the existing code was added because creating threads was slow on<br>
windows, but it is not used on windows anymore.<br>
<br>
Cheers,<br>
Rafael<br>
<br>
Rafael Avila de Espindola <<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>> writes:<br>
<br>
> NAKAMURA Takumi <<a href="mailto:geek4civic@gmail.com" target="_blank">geek4civic@gmail.com</a>> writes:<br>
><br>
>> It was discussed in <a href="https://reviews.llvm.org/D39038" rel="noreferrer" target="_blank">https://reviews.llvm.org/D39038</a><br>
>><br>
>> I suffered when check-lld behaves flaky. For example;<br>
>> <a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19673" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19673</a><br>
>><br>
>> I have been investigating and I guess it triggered bug or something in<br>
>> libpthread or Linux kernel.<br>
>> pthread_detach() in std::thread::detach() is crashing with segv.<br>
>> Seems pthread (internal struct in Linux nptl) is inaccessible.<br>
>> The crash is reproducible w/o std::thread, but with libpthread.<br>
>> In my environment, crash can be seen several times per million attempt.<br>
>><br>
>> This is my testcase. (in Parallel.cpp)<br>
>><br>
>>         pthread_t th;<br>
>>         auto r = pthread_create(&th, nullptr, worker_stub, (void*)this);<br>
>>         (void)r;<br>
>>         assert(r == 0);<br>
>>         auto p = reinterpret_cast<volatile int*>(th);<br>
>>         for (int j = 0; j < 1000 * 1000; ++j)<br>
>>           *p;<br>
>>         pthread_detach(th);<br>
><br>
><br>
> Can you try if you get a crash with just<br>
><br>
> ------------------------------<br>
> #include <pthread.h><br>
> #include <assert.h><br>
> static void *worker_stub(void *) {<br>
>   return nullptr;<br>
> }<br>
> int main() {<br>
>   pthread_t th;<br>
>  auto r = pthread_create(&th, nullptr, worker_stub, (void*)42);<br>
>  (void)r;<br>
>  assert(r == 0);<br>
>  auto p = reinterpret_cast<volatile int*>(th);<br>
>  for (int j = 0; j < 1000 * 1000; ++j)<br>
>    *p;<br>
>  pthread_detach(th);<br>
> }<br>
> ------------------------------<br>
><br>
> Cheers,<br>
> Rafael<br>
</blockquote></div>