Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These are various small and large changes to the
ThreadPool
code.My main goal here is to work toward code that is easier to reason about and easier to change.
More specific goals that this code may facilitate:
@todo
array would probably be better implemented as aQueue
.Queue
s come with built in concurrency-facilitating behavior (they have an internal mutex so no outside mutext is needed and#pop
sleeps when the queue is empty and returnsnil
when theQueue
has been shut down), which I believe will make the code nicer and possibly more performant. See an example of how this can be used here: patrickxb/stathat@b47dd80There are several
Thread
methods thatThreadPoolWorker
simply passes down to theThread
that it manages. This could be a smell... but I think it can lead to further improvements in which coordination code goes where. Perhaps we can keep iterating so that ashutdown
command does several of the things needed for managing an individual thread, without need for fine-grained thread coordination at the topThreadPool
level.related: #1577, #1586, #1588
It's a work in progress. I'd love to get some feedback to direct my continued work. I would recommend looking at the commits one by one. "hide whitespace changes" will help with some of them.
I'm guessing that you will like some of the initial aesthetic changes. If so, I can make another PR with just those so we can get those into master and simplify this PR.