[PATCH] D32826: Move Parallel.h from LLD to LLVM

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 14:04:44 PDT 2017


labath added inline comments.


================
Comment at: llvm/include/llvm/Support/Parallel.h:125
+      for (size_t i = 1; i < threadCount; ++i) {
+        std::thread([=] { work(); }).detach();
+      }
----------------
labath wrote:
> There's a somewhat annoying bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19951> present in all versions of glibc, which can lead to crashes if the thread happens to exit while it is being detached. I see no synchronization here which would prevent that, so I guess whether the crash happens depends on the type of work we will do here.
> 
> The workaround is to add some synchronization which makes sure these two things don't happen concurrently (adds some overhead, but if done right it can be negligible), or create the threads in a detached state (impossible through the std::thread API).
Ok, I think the situation is not as bad as I first thought. The synchronization in the Latch destructor should make sure this does not happen for the worker threads.

This just leaves the spawner thread as a question. It may be possible it will be slow enough that it will not trigger the bug, but heavy system load can do wonders to thread scheduling...


https://reviews.llvm.org/D32826





More information about the llvm-commits mailing list