0

[threadpool] Prevent ThreadPool from running more tasks than desired.

Problem description: crbug.com/1210974

Solution: Do not release the ThreadGroup lock between deciding that
a worker can get work and incrementing the number of running tasks.

Will this change break something else? This change puts the call to
CanGetWorkLockRequired() back to where it was prior to
https://crrev.com/c/2568903. It was moved to avoid checking if more
workers are needed in the case where the current worker cannot get
work. This is an unnecessary optimization.

Fixed: 1210974

R=etiennep

Change-Id: Ic22dfbca6062440ffc9280f6bfee6bb04d659f35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2905916
Auto-Submit: François Doray <fdoray@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#886301}
This commit is contained in:
Francois Doray
2021-05-25 15:40:14 +00:00
committed by Chromium LUCI CQ
parent 17ce20c8ea
commit adda67457d

@ -586,9 +586,6 @@ RegisteredTaskSource ThreadGroupImpl::WorkerThreadDelegateImpl::GetWork(
DCHECK(ContainsWorker(outer_->workers_, worker));
if (!CanGetWorkLockRequired(&executor, worker))
return nullptr;
// Use this opportunity, before assigning work to this worker, to create/wake
// additional workers if needed (doing this here allows us to reduce
// potentially expensive create/wake directly on PostTask()).
@ -599,6 +596,9 @@ RegisteredTaskSource ThreadGroupImpl::WorkerThreadDelegateImpl::GetWork(
executor.FlushWorkerCreation(&outer_->lock_);
}
if (!CanGetWorkLockRequired(&executor, worker))
return nullptr;
RegisteredTaskSource task_source;
TaskPriority priority;
while (!task_source && !outer_->priority_queue_.IsEmpty()) {