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

Issue 8416019: Add a sequenced worker pool (Closed)

Created:
9 years, 1 month ago by brettw
Modified:
8 years, 11 months ago
CC:
chromium-reviews, joi+watch-content_chromium.org, darin-cc_chromium.org, jam, michaeln, dpranke-watch+content_chromium.org
Visibility:
Public.

Description

Add a sequenced worker pool. This allows tasks to be put in the worker pool with optional sequencing semantics for consumers that must run a bunch of stuff in order on a background thread, but don't particularly care about which thread. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=116078

Patch Set 1 #

Patch Set 2 : '' #

Patch Set 3 : '' #

Total comments: 26

Patch Set 4 : '' #

Total comments: 18

Patch Set 5 : '' #

Total comments: 16

Patch Set 6 : '' #

Patch Set 7 : '' #

Patch Set 8 : '' #

Total comments: 19

Patch Set 9 : '' #

Patch Set 10 : '' #

Total comments: 31

Patch Set 11 : '' #

Total comments: 5

Patch Set 12 : '' #

Patch Set 13 : '' #

Patch Set 14 : '' #

Patch Set 15 : '' #

Total comments: 5

Patch Set 16 : '' #

Patch Set 17 : '' #

Total comments: 2

Patch Set 18 : '' #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+1244 lines, -0 lines) Patch
M base/base.gyp View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +1 line, -0 lines 0 comments Download
M base/base.gypi View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +2 lines, -0 lines 0 comments Download
A base/threading/sequenced_worker_pool.h View 1 2 3 4 5 6 7 8 9 10 11 12 1 chunk +206 lines, -0 lines 0 comments Download
A base/threading/sequenced_worker_pool.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 chunk +630 lines, -0 lines 2 comments Download
A base/threading/sequenced_worker_pool_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +405 lines, -0 lines 0 comments Download

Messages

Total messages: 58 (0 generated)
brettw
9 years, 1 month ago (2011-10-28 18:03:54 UTC) #1
jar (doing other things)
IMO, this whole activity cries out for using condition variables. They take care of so ...
9 years, 1 month ago (2011-10-29 02:37:14 UTC) #2
brettw
No new patch, but I tried to answer your bigger questions. http://codereview.chromium.org/8416019/diff/3002/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): ...
9 years, 1 month ago (2011-10-29 05:31:18 UTC) #3
brettw
I'm thinking of this as "replace the FILE thread with something more flexible" rather than ...
9 years, 1 month ago (2011-10-29 05:31:29 UTC) #4
brettw
To add some color to what I was talking about in the previous message... For ...
9 years, 1 month ago (2011-10-29 06:07:23 UTC) #5
jar (doing other things)
Those comments provide a lot more motivation. To summarize: You're not looking at replacing the ...
9 years, 1 month ago (2011-10-29 07:05:32 UTC) #6
brettw
I started writing a version with condition vars and it didn't seem like it would ...
9 years, 1 month ago (2011-11-22 22:58:41 UTC) #7
michaeln
drive-by: it'd be nice to have this class defined in the 'base' library, i'd like ...
9 years, 1 month ago (2011-11-23 01:58:25 UTC) #8
jar (doing other things)
A high-level API fear is that we really need an enumerated list of of psuedo-threads, ...
9 years, 1 month ago (2011-11-23 20:08:16 UTC) #9
brettw
On 2011/11/23 20:08:16, jar wrote: > A high-level API fear is that we really need ...
9 years, 1 month ago (2011-11-23 20:43:14 UTC) #10
brettw
http://codereview.chromium.org/8416019/diff/7001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/7001/content/common/sequenced_worker_pool.cc#newcode168 content/common/sequenced_worker_pool.cc:168: SequencedWorkerPool::Inner::GetSequenceToken() { I think an enum destroys the whole ...
9 years, 1 month ago (2011-11-23 21:01:13 UTC) #11
jar (doing other things)
I think the enum list is the natural way to go. Your concern in a ...
9 years, 1 month ago (2011-11-23 22:00:04 UTC) #12
jar (doing other things)
On Wed, Nov 23, 2011 at 1:01 PM, <brettw@chromium.org> wrote: > > Is there an ...
9 years, 1 month ago (2011-11-23 22:13:08 UTC) #13
brettw
On Wed, Nov 23, 2011 at 2:13 PM, Jim Roskind <jar@chromium.org> wrote: > > > ...
9 years, 1 month ago (2011-11-23 22:21:26 UTC) #14
brettw
Michael: I'm going to leave this in content for now. We can move it later. ...
9 years ago (2011-11-25 18:33:38 UTC) #15
brettw
I uploaded a new patch using condition variables. The code is longer. Currently it deadlocks ...
9 years ago (2011-11-25 19:26:03 UTC) #16
jar (doing other things)
Thanks for looking at the alternative. As the comments below show, you didn't fully drink ...
9 years ago (2011-11-25 23:06:08 UTC) #17
jar (doing other things)
http://codereview.chromium.org/8416019/diff/19001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/19001/content/common/sequenced_worker_pool.cc#newcode336 content/common/sequenced_worker_pool.cc:336: task.task.Run(); One other thing... it is common to signal ...
9 years ago (2011-11-26 01:25:59 UTC) #18
brettw
http://codereview.chromium.org/8416019/diff/19001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/19001/content/common/sequenced_worker_pool.cc#newcode292 content/common/sequenced_worker_pool.cc:292: dropped_tasks.push_back(*i); How can you guarantee that there is a ...
9 years ago (2011-11-26 01:54:40 UTC) #19
jar (doing other things)
I continue to think this is the perfect job for CVs. I think this sort ...
9 years ago (2011-11-26 06:45:35 UTC) #20
jar (doing other things)
I thought about it more, and think the deletion question for un-run tasks may be ...
9 years ago (2011-11-26 15:34:23 UTC) #21
jar (doing other things)
Question: If you use a message loop based implementation, how would you correctly(?) handle having ...
9 years ago (2011-11-26 15:54:43 UTC) #22
brettw
I agree that the cond vars are the correct CS way to solve this problem, ...
9 years ago (2011-11-26 21:23:47 UTC) #23
brettw
> Bottom line: I think that IF you're going to delete tasks that have not ...
9 years ago (2011-11-26 21:25:54 UTC) #24
brettw
I see the problem now. We can't delete tasks in sequence without extra threads. I'll ...
9 years ago (2011-11-26 21:45:20 UTC) #25
brettw
I see the problem now. We can't delete tasks in sequence without extra threads. I'll ...
9 years ago (2011-11-26 21:45:22 UTC) #26
brettw
New snap up. This does a best effort to delete tasks while keeping everything sequenced. ...
9 years ago (2011-11-26 22:04:58 UTC) #27
michaeln
On 2011/11/25 18:33:38, brettw wrote: > Michael: I'm going to leave this in content for ...
9 years ago (2011-11-28 21:30:51 UTC) #28
brettw
On 2011/11/28 21:30:51, michaeln wrote: > On 2011/11/25 18:33:38, brettw wrote: > > Michael: I'm ...
9 years ago (2011-11-28 21:46:13 UTC) #29
michaeln
> How do you do today what you want to do with this thread pool? ...
9 years ago (2011-11-28 23:36:12 UTC) #30
jar (doing other things)
Again... if you're hating CVs... and havin' to listen to me yap... please feel free ...
9 years ago (2011-11-29 18:44:15 UTC) #31
brettw
New snap up. I'll move this to base but I didn't want to do it ...
9 years ago (2011-12-01 02:44:57 UTC) #32
brettw
Actually, I think I figured out how to create threads outside of the lock. We ...
9 years ago (2011-12-01 18:23:25 UTC) #33
michaeln
Thnx! > I'll move this to base but I didn't want to do it now ...
9 years ago (2011-12-02 02:43:07 UTC) #34
brettw
Thread creation now happens outside of the lock. It's kind of subtle, I hope the ...
9 years ago (2011-12-02 04:35:26 UTC) #35
jar (doing other things)
Most of my comments focus on chasing the following pattern (which you mostly do already). ...
9 years ago (2011-12-09 19:01:47 UTC) #36
willchan no longer on Chromium
Just saw this while skimming the code. http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode537 content/common/sequenced_worker_pool.cc:537: linked_ptr<Worker> new_thread(new ...
9 years ago (2011-12-09 21:41:47 UTC) #37
jar (doing other things)
http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode537 content/common/sequenced_worker_pool.cc:537: linked_ptr<Worker> new_thread(new Worker(this, thread_number)); I thought the access to ...
9 years ago (2011-12-09 22:13:58 UTC) #38
brettw
I fixed everything except the one thing noted below. http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode362 content/common/sequenced_worker_pool.cc:362: ...
9 years ago (2011-12-10 05:42:27 UTC) #39
jar (doing other things)
http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode362 content/common/sequenced_worker_pool.cc:362: cond_var_.Signal(); AutoLock() is on line 326, which is the ...
9 years ago (2011-12-10 17:08:03 UTC) #40
brettw
http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode362 content/common/sequenced_worker_pool.cc:362: cond_var_.Signal(); You are incorrect, the AutoLock is not at ...
9 years ago (2011-12-10 17:25:28 UTC) #41
brettw
I originally had the created threads flag be an integer count of the number of ...
9 years ago (2011-12-10 17:29:37 UTC) #42
jar (doing other things)
http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/43001/content/common/sequenced_worker_pool.cc#newcode362 content/common/sequenced_worker_pool.cc:362: cond_var_.Signal(); You are correct. I was incorrect. Sorry... I ...
9 years ago (2011-12-10 18:41:43 UTC) #43
michaeln
drive by comments, looks pretty nice http://codereview.chromium.org/8416019/diff/49001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/49001/content/common/sequenced_worker_pool.cc#newcode16 content/common/sequenced_worker_pool.cc:16: #include "base/synchronization/waitable_event.h" is ...
9 years ago (2011-12-14 20:37:46 UTC) #44
jar (doing other things)
With nits mentioned in the drive by... LGTM http://codereview.chromium.org/8416019/diff/49001/content/common/sequenced_worker_pool.cc File content/common/sequenced_worker_pool.cc (right): http://codereview.chromium.org/8416019/diff/49001/content/common/sequenced_worker_pool.cc#newcode523 content/common/sequenced_worker_pool.cc:523: if ...
9 years ago (2011-12-14 23:47:15 UTC) #45
brettw
I addressed Michael's comments except for the PrepareToStartAdditionalThreadIfHelpful one. It wasn't clear to me hwo ...
9 years ago (2011-12-18 16:53:53 UTC) #46
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/brettw@chromium.org/8416019/96003
8 years, 12 months ago (2011-12-27 16:51:47 UTC) #47
commit-bot: I haz the power
Try job failure for 8416019-96003 (retry) (retry) on win_rel for steps "base_unittests, safe_browsing_tests" (clobber build). ...
8 years, 12 months ago (2011-12-27 20:29:14 UTC) #48
brettw
The tests were flaky and I spent a really really long time figuring it out. ...
8 years, 12 months ago (2011-12-29 05:53:15 UTC) #49
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/brettw@chromium.org/8416019/102001
8 years, 12 months ago (2011-12-29 17:17:45 UTC) #50
jar (doing other things)
I just saw your commnent about having trouble with the unit tests. My apologies. I ...
8 years, 12 months ago (2011-12-29 18:15:45 UTC) #51
brettw
http://codereview.chromium.org/8416019/diff/102001/base/threading/sequenced_worker_pool_unittest.cc File base/threading/sequenced_worker_pool_unittest.cc (right): http://codereview.chromium.org/8416019/diff/102001/base/threading/sequenced_worker_pool_unittest.cc#newcode54 base/threading/sequenced_worker_pool_unittest.cc:54: Ah, good catch. I'll fix this.
8 years, 12 months ago (2011-12-29 18:23:16 UTC) #52
brettw
New snap up using cond vars instead of events. I think this is a bit ...
8 years, 11 months ago (2011-12-30 20:29:51 UTC) #53
jar (doing other things)
lgtm
8 years, 11 months ago (2011-12-31 08:21:21 UTC) #54
brettw
I found another real bug that causes test flakyness due to a race condition on ...
8 years, 11 months ago (2011-12-31 17:38:43 UTC) #55
jar (doing other things)
See comments below. If you're not worried, and equally tired, then LGTM. If you encounter ...
8 years, 11 months ago (2011-12-31 19:06:10 UTC) #56
brettw
You're right! I moved this insertion into the list to the beginning of the actual ...
8 years, 11 months ago (2011-12-31 19:30:44 UTC) #57
jar (doing other things)
8 years, 11 months ago (2011-12-31 20:27:27 UTC) #58
lgtm

http://codereview.chromium.org/8416019/diff/117001/base/threading/sequenced_w...
File base/threading/sequenced_worker_pool.cc (right):

http://codereview.chromium.org/8416019/diff/117001/base/threading/sequenced_w...
base/threading/sequenced_worker_pool.cc:336:
threads_.push_back(linked_ptr<Worker>(this_worker));
This is nicer and cleaner too.  I like that it is right next to the clearing of
thread_being_created_.

http://codereview.chromium.org/8416019/diff/117001/base/threading/sequenced_w...
base/threading/sequenced_worker_pool.cc:540: threads_.size() < max_threads_ &&
Thinking about it it more, I remembered that you're protected from this race by
the boolean thread_being_created_.  While that is set, we never test
threads_.size(), which probably avoids the race.

Powered by Google App Engine
This is Rietveld 408576698