[PATCH] D36607: [Support/Parallel] - Do not spawn thread for single/last task.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 00:50:16 PDT 2017


grimar added a comment.

In https://reviews.llvm.org/D36607#843789, @ruiu wrote:

> George,
>
> First of all, busy-waiting is a no-no, so we can't eliminate the condition variable from the thread pool. When a thread has to wait for some event to happen, it has to use a condition variable to put itself into the "blocked" state instead of busy-looping until the condition is met. That is in general true even if using busy loops makes your program faster, as your OS supports multiple processes and you don't want one process eat up all CPU resources.


Sure, I would not suggest busy-waiting for generic thread pool use case like this. It was experiment.
Idea mentioned by Davide about "spinning for a certain number of cycles decreasing a variable each time (and going to sleep when the variable reaches zero)" can probably fit nice here though.
Since when we start doing `parallel_for` we assume each thread will have several tasks, it looks reasonable to check if there are any more before going to sleep after each one.

> This patch look fine though. But the description is a bit pointless. That is why you are getting so much questions about this patch. You generally don't want to copy-pasta code to describe what you are doing (which applies not only this patch but also your other patches). Instead, use prose to describe what you are trying to achieve with a patch.

I'll try. Thank you.


https://reviews.llvm.org/D36607





More information about the llvm-commits mailing list