Newly added ThreadPoolExecutor causes deadlock in lld

Recently added ThreadPoolExecutor limits number of worker threads to number of logical processors.

This might cause deadlock in case one’s doing nested calls to parallel_for_each, like this:

void Bar() { … }

void Foo() {

parallel_for_each(Begin, End, Bar);


void main() {

parallel_for_each(Begin, End, Foo);


This happens because both parallel_for_each and parallel_for_each_n wait for task group to finish

and this may actually never happen in case they’re executed from worker threads. In such case worker

thread is blocked in TaskGroup destructor. This does happen in lld, when it writes output sections as

there is a nested call to parallel_for_each_n to write each output section inputs.

I reverted my change so that there’s no nested parallel_for_each calls in lld.

We should fix ThreadPoolExecutor so that it can be called from nested loops. Quote from