Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Issue 9651026: Clean up condition variable usage in SequencedWorkerPool (Closed)

Created:
8 years, 9 months ago by akalin
Modified:
8 years, 9 months ago
CC:
chromium-reviews, brettw-cc_chromium.org, Sigurður Ásgeirsson
Visibility:
Public.

Description

Clean up condition variable usage in SequencedWorkerPool Add unit test for spurious work signal behavior. Split cond_var_ into multiple condition variables; one for each distinct condition. Document exactly when each condition variable is waited on. Restrict the thread that SWP::Shutdown() can be called from. Fix brace usage in destructor. BUG=117469 TEST= Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=126241

Patch Set 1 #

Patch Set 2 : Address comments #

Total comments: 25

Patch Set 3 : Address jar's comments #

Total comments: 6

Patch Set 4 : Address nits #

Unified diffs Side-by-side diffs Delta from patch set Stats (+108 lines, -28 lines) Patch
M base/threading/sequenced_worker_pool.h View 1 2 1 chunk +9 lines, -1 line 0 comments Download
M base/threading/sequenced_worker_pool.cc View 1 2 3 14 chunks +87 lines, -27 lines 0 comments Download
M base/threading/sequenced_worker_pool_unittest.cc View 1 2 1 chunk +12 lines, -0 lines 0 comments Download

Messages

Total messages: 13 (0 generated)
akalin
+brettw for review +siggi, feel free to chime in if you notice anything (the more ...
8 years, 9 months ago (2012-03-09 04:04:54 UTC) #1
akalin
+jar for review instead, as brett says you're a better person to review this
8 years, 9 months ago (2012-03-09 05:18:18 UTC) #2
Sigurður Ásgeirsson
Have not reviewed in detail, but it strikes me that it would be interesting to ...
8 years, 9 months ago (2012-03-09 11:59:20 UTC) #3
akalin
On 2012/03/09 11:59:20, Sigurður Ásgeirsson wrote: > Have not reviewed in detail, but it strikes ...
8 years, 9 months ago (2012-03-09 19:39:07 UTC) #4
Sigurður Ásgeirsson
I don't feel qualified to review this change on merits, but I do feel it's ...
8 years, 9 months ago (2012-03-12 13:01:40 UTC) #5
jar (doing other things)
In addition to a bunch of questions about this CL, I'm still questioning whether we ...
8 years, 9 months ago (2012-03-12 17:39:12 UTC) #6
akalin
Addressed all comments. PTAL. http://codereview.chromium.org/9651026/diff/6001/base/threading/sequenced_worker_pool.cc File base/threading/sequenced_worker_pool.cc (left): http://codereview.chromium.org/9651026/diff/6001/base/threading/sequenced_worker_pool.cc#oldcode387 base/threading/sequenced_worker_pool.cc:387: { On 2012/03/12 17:39:13, jar ...
8 years, 9 months ago (2012-03-12 18:34:34 UTC) #7
akalin
On 2012/03/12 17:39:12, jar wrote: > In addition to a bunch of questions about this ...
8 years, 9 months ago (2012-03-12 18:39:20 UTC) #8
akalin
On 2012/03/12 18:39:20, akalin wrote: > But you're right about has_work_cv_/can_shutdown_cv_. If you really want, ...
8 years, 9 months ago (2012-03-12 19:14:16 UTC) #9
jar (doing other things)
Your scenario is what I (tried to) talk about with regard to the Broadcast(). If ...
8 years, 9 months ago (2012-03-12 19:35:54 UTC) #10
jar (doing other things)
LGTM Nits and comments below don't require or request any changes to land. http://codereview.chromium.org/9651026/diff/6001/base/threading/sequenced_worker_pool.cc File ...
8 years, 9 months ago (2012-03-12 19:42:36 UTC) #11
akalin
On 2012/03/12 19:35:54, jar wrote: > Your scenario is what I (tried to) talk about ...
8 years, 9 months ago (2012-03-12 20:20:22 UTC) #12
akalin
8 years, 9 months ago (2012-03-12 20:42:15 UTC) #13
submitting as soon as trybots pass base_unittests

Thanks for the review!

http://codereview.chromium.org/9651026/diff/6001/base/threading/sequenced_wor...
File base/threading/sequenced_worker_pool.cc (left):

http://codereview.chromium.org/9651026/diff/6001/base/threading/sequenced_wor...
base/threading/sequenced_worker_pool.cc:404: cond_var_.Signal();
On 2012/03/12 19:42:36, jar wrote:
> I *think* you are correct.  This is a slightly (IMO) abnormal pattern that we
> get from this use of CVs, in that we get a signal for each new task, and work
> doesn't just spontaneously start appearing without signals (i.e., tasks in our
> queue don't just quietly insert more tasks).  
> 
> IMO, it is a little subtle, and I'm used to a simple "always signal when you
> take on work and can't Wait()," pattern.
> 
> I think this might therefore be overkill... but ends up having no real
> consequence (I think).  It sure makes it easy to see correctness though, IMO.

I see.  Okay, I just added a comment as to why it's left in.

http://codereview.chromium.org/9651026/diff/12001/base/threading/sequenced_wo...
File base/threading/sequenced_worker_pool.cc (right):

http://codereview.chromium.org/9651026/diff/12001/base/threading/sequenced_wo...
base/threading/sequenced_worker_pool.cc:367: int
SequencedWorkerPool::Inner::GetWorkSignalCountForTesting() const {
On 2012/03/12 19:42:36, jar wrote:
> nit: It bugs me a little that we've added this must testing infrastructure...
> and the optimizer will probably never be able to realize these are not needed.

> I wish these could be done in the unit test file, with minimal access given to
a
> FriendTest class.  For instance, it would be nice if we only handed the test
> class private access to our lock, or such, and let it craft CVs to its heart
> content :-/.
> 
> For now, I'll focus on this CL, and its correctness... but I wanted to pass on
> that thought.

I think I can remove this variable and instead add another method to the
TestingObserver class that is called whenever has_work_cv_ is signalled.  I'll
do that in another CL.

http://codereview.chromium.org/9651026/diff/12001/base/threading/sequenced_wo...
base/threading/sequenced_worker_pool.cc:469: can_shutdown_cv_.Signal();
On 2012/03/12 19:42:36, jar wrote:
> Placing this here is probably more optimal than I had envisioned.  I figured
> you'd just put the extra signal outside the lock, and let the controlling
> process (if any) check to see if CanShutdown() (which it is already definitely
> planning to check, watching for spurious signals!).

Yeah, I think that's simpler.  I moved it out.

http://codereview.chromium.org/9651026/diff/12001/base/threading/sequenced_wo...
base/threading/sequenced_worker_pool.cc:470: }
On 2012/03/12 19:42:36, jar wrote:
> nit: Add comment: // Release lock_.

Done.

Powered by Google App Engine
This is Rietveld 408576698