[PATCH] D25784: [Support] ThreadPool: Don't spawn any threads when ThreadCount = 1
Mehdi AMINI via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 19 14:00:07 PDT 2016
mehdi_amini added a comment.
In https://reviews.llvm.org/D25784#574651, @vsk wrote:
> In https://reviews.llvm.org/D25784#574641, @mehdi_amini wrote:
> > That seems fine and makes sense to me from an API point of view.
> > I'm not sure how to translate this to the user though: I don't expect someone to run `-threads=0`. And we're back to special casing in the client: `ThreadPool Pool(ThreadCount == 1 ? 0 : ThreadCount);` which isn't great either.
> 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).
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?
More information about the llvm-commits