<div dir="ltr">It was discussed in <a href="https://reviews.llvm.org/D39038">https://reviews.llvm.org/D39038</a><div><br></div><div>I suffered when check-lld behaves flaky. For example; <a href="http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19673">http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19673</a></div><div><br></div><div>I have been investigating and I guess it triggered bug or something in libpthread or Linux kernel.</div><div>pthread_detach() in std::thread::detach() is crashing with segv.</div><div>Seems pthread (internal struct in Linux nptl) is inaccessible.</div><div>The crash is reproducible w/o std::thread, but with libpthread.</div><div>In my environment, crash can be seen several times per million attempt.</div><div><br></div><div>This is my testcase. (in Parallel.cpp)</div><div><br></div><div><div>        pthread_t th;</div><div>        auto r = pthread_create(&th, nullptr, worker_stub, (void*)this);</div><div>        (void)r;</div><div>        assert(r == 0);</div><div>        auto p = reinterpret_cast<volatile int*>(th);<br></div><div>        for (int j = 0; j < 1000 * 1000; ++j)</div><div>          *p;</div><div>        pthread_detach(th);<br></div></div><div><br></div><div>Accessing *p sometimes raises segv.</div><div><br></div><div>Ideally, Linux (or distro) should be fixed, but I suppose the distro, Ubuntu 14.04 is widely used.</div><div>I would like to propose we could avoid std::thread().detach()</div><div><br></div><div>As far as I tried, this successfully runs to me with million of iterations.</div><div>- Use naked pthread_create()</div><div>  a) Create the thread with PTHREAD_CREATE_DETACHED</div><div>  b) Do pthread_detach(pthread_self()) in the worker thread.</div><div><br></div><div>Note, (b) doesn't work with std::thread.</div><div><br></div><div>Takumi</div></div>