[PATCH] D25784: [Support] ThreadPool: Don't spawn any threads when ThreadCount = 1

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 14:40:47 PDT 2016


vsk added a comment.

In https://reviews.llvm.org/D25784#574739, @mehdi_amini wrote:

> > Good point. Wdyt of adding 'bool PreferSequential = false' to the constructors? The meaning of 'PreferSequential' would be `ThreadCount = (PreferSequential && MaxThreadCount == 1) ? 0 : MaxThreadCount`. That way, users can opt-in to executing all the tasks in wait().
>
> That looks weird to create a threads pool and saying at the same time that I "prefer sequential":  `ThreadPool Pool(MaxThreadCount, /* PreferSequential */ true);` ; it's almost contradictory (though I see how it could simplify the client code somehow).


Hm, yeah.

> This "optimization" seems like a difficult thing to fit in the API. I'm not very inspired right now, so I haven't any great suggestion.
> 
> By the way, did you have a particular client in mind? The pool isn't really designed for very lightweight task but rather "heavier" one, where the cost of spawning a thread shouldn't be significant?

I'll try and think of a more natural way to do this. Maybe adding support for the ThreadCount = 0 case is the simplest option.

The client I had in mind is llvm-cov, where each thread writes out a coverage report to disk. It is not relatively expensive to spawn a thread in this context. But it would be nice to just have one code path for the threaded+non-threaded cases instead of two.


https://reviews.llvm.org/D25784





More information about the llvm-commits mailing list