std::thread::detach() rarely crashes in Parallel.cpp

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 14:50:01 PDT 2017


And an even simpler thing to try: start all the threads from the main
thread.

I think the existing code was added because creating threads was slow on
windows, but it is not used on windows anymore.

Cheers,
Rafael

Rafael Avila de Espindola <rafael.espindola at gmail.com> writes:

> NAKAMURA Takumi <geek4civic at gmail.com> writes:
>
>> It was discussed in https://reviews.llvm.org/D39038
>>
>> I suffered when check-lld behaves flaky. For example;
>> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19673
>>
>> I have been investigating and I guess it triggered bug or something in
>> libpthread or Linux kernel.
>> pthread_detach() in std::thread::detach() is crashing with segv.
>> Seems pthread (internal struct in Linux nptl) is inaccessible.
>> The crash is reproducible w/o std::thread, but with libpthread.
>> In my environment, crash can be seen several times per million attempt.
>>
>> This is my testcase. (in Parallel.cpp)
>>
>>         pthread_t th;
>>         auto r = pthread_create(&th, nullptr, worker_stub, (void*)this);
>>         (void)r;
>>         assert(r == 0);
>>         auto p = reinterpret_cast<volatile int*>(th);
>>         for (int j = 0; j < 1000 * 1000; ++j)
>>           *p;
>>         pthread_detach(th);
>
>
> Can you try if you get a crash with just
>
> ------------------------------
> #include <pthread.h>
> #include <assert.h>
> static void *worker_stub(void *) {
>   return nullptr;
> }
> int main() {
>   pthread_t th;
>  auto r = pthread_create(&th, nullptr, worker_stub, (void*)42);
>  (void)r;
>  assert(r == 0);
>  auto p = reinterpret_cast<volatile int*>(th);
>  for (int j = 0; j < 1000 * 1000; ++j)
>    *p;
>  pthread_detach(th);
> }
> ------------------------------
>
> Cheers,
> Rafael


More information about the llvm-commits mailing list