• Etienne Pierre-doray's avatar
    [Jobs API]: Use worker_lock in JobTaskSource. · 6eb566d2
    Etienne Pierre-doray authored
    Possible race when Join():
    - thread A: Join: worker_released_condition_->Wait()
    - thread C: WillRunTask:
                  GetMaxConcurrency() returns > 0
    - thread B: already running, finishes all the work
                  GetMaxConcurrency() goes 0
    - thread B: DidProcessTask:
                  worker_released_condition_->Signal(),
    - thread A: Join returns (GetMaxConcurrency() is 0)
    - thread C: TryIncrementWorkerCountFromWorkerRelease
                  worker count goes 1
    - thread C: runs worker_task after Join
    
    To fix race when Joining, all writes to |state_| are protected by
    |worker_lock|. Memory ordering is no longer necessary.
    
    Alternative: cancel before Join returns with a compare and swap and
    loop again if new workers.
    
    Change-Id: I4e478ffae2bdaec56386739f78de089d0e74e42c
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248159
    Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
    Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#781453}
    6eb566d2
job_task_source.h 7.96 KB