[PATCH] D42573: [wip] The new threading implementation

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 31 07:45:18 PST 2018


ilya-biryukov added inline comments.


================
Comment at: clangd/TUScheduler.cpp:220
+
+  GCThread.cleanupFile(std::move(Data->Worker));
 }
----------------
sammccall wrote:
> in the spirit of "just spawn a thread, and write direct code"...
> 
> can we just spawn a shared_ptr<std::thread> to do the work here, and replace GCThread with a vector<weak_ptr<std::thread>>.
> Then ~TUScheduler could just loop through:
> 
>   for (const auto &WeakThread : Cleanups)
>     if (auto SharedThread = WeakThread.lock()) // thread may have died already
>       SharedThread->join();
> 
> might be simpler? You need to lock the Cleanups vector, but no fiddling with CVs etc.
The problem is that stored vector will have unbounded growth, and I think it shouldn't. 
What we could do instead, though, is to have a counter that increments with each spawned request and wait for it to go down to 0 when TUScheduler dies. That should be simpler than what we have now and we have vectors that can grow indefinitely.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42573





More information about the cfe-commits mailing list