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

Issue 2145463002: Modernize base::Thread (Closed)

Created:
4 years, 5 months ago by gab
Modified:
4 years, 4 months ago
Reviewers:
danakj, Wez
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Modernize base::Thread No-op cleanup extracted from https://codereview.chromium.org/2135413003/#ps40001 In this CL: - Explicitly document the threading requirements of the API after grokking its use of locks in some places and lack of in some others) - (It's mostly thread unsafe; except for a few calls which are okay from the owner as well as the underlying thread; and one method which is actually thread-safe) - Add assertions as such (and catch issues on try bots :-O -- http://crbug.com/629139) - Remove |thread_lock_| which is unnecessary under the documented conditions (delayed until http://crbug.com/629139 is fixed..). - C++11 member initializers (makes it cleaner to add new POD members and makes constructors simpler -- e.g. |run_loop_| was uninitialized) - Assertions and tests for current API which allows Start/Stop/Start cycles but wasn't tested... (actually more than that is poorly/not tested in this class but I'm merely adding tests for parts I'm stressing in my actual follow-up CL). - Comment nits - Make event-based tests use WaitableEvent instead of sleeping + toggling a bool. BUG=629716, 629139 Committed: https://crrev.com/1734a80f1519819eb6a3d8eb43064f8fb2c2e067 Cr-Commit-Position: refs/heads/master@{#407265}

Patch Set 1 #

Patch Set 2 : Allow message_loop()/task_runner() getters from underlying thread too #

Patch Set 3 : Temporarily disable thread-safe check in Stop() per crbug/629139 #

Patch Set 4 : Allow message_loop()/task_runner() access from externally synchronized threads. #

Patch Set 5 : use |message_loop_| instead of |running_| to assert Start()'s synchronization #

Patch Set 6 : only attach to sequence on Start #

Patch Set 7 : merge up to r406471 #

Patch Set 8 : Disable check in StopSoon() as in Stop() per crbug/629139 #

Patch Set 9 : Disable check in IsRunning() per crbug/629139 and add extra logging. #

Total comments: 19

Patch Set 10 : Disable check in message_loop() per crbug.com/629139#c6 :-( #

Patch Set 11 : review:danakj #

Total comments: 2

Patch Set 12 : comment nit #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+138 lines, -66 lines) Patch
M base/threading/thread.h View 1 2 3 4 5 6 7 8 9 10 11 9 chunks +49 lines, -13 lines 0 comments Download
M base/threading/thread.cc View 1 2 3 4 5 6 7 8 9 10 10 chunks +49 lines, -43 lines 4 comments Download
M base/threading/thread_unittest.cc View 2 chunks +40 lines, -10 lines 0 comments Download

Messages

Total messages: 85 (67 generated)
gab
Dana PTAL, lots of work went into making this pass (turns out people don't always ...
4 years, 5 months ago (2016-07-21 19:15:25 UTC) #47
danakj
This is great https://codereview.chromium.org/2145463002/diff/180001/base/threading/thread.cc File base/threading/thread.cc (left): https://codereview.chromium.org/2145463002/diff/180001/base/threading/thread.cc#oldcode113 base/threading/thread.cc:113: AutoLock lock(thread_lock_); I think you do ...
4 years, 5 months ago (2016-07-21 19:43:26 UTC) #50
gab
Dana, all done, PTAnL, thanks! PS: Had to disable one more test (and still getting ...
4 years, 5 months ago (2016-07-22 16:02:55 UTC) #55
gab
On 2016/07/22 18:13:16, gab wrote: > The CQ bit was checked by https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=gab@chromium.org to run ...
4 years, 5 months ago (2016-07-22 18:13:35 UTC) #61
gab
On 2016/07/22 17:29:31, commit-bot: I haz the power wrote: > Dry run: This issue passed ...
4 years, 5 months ago (2016-07-22 18:13:59 UTC) #63
Avi (use Gerrit)
drive-by grammaring https://codereview.chromium.org/2145463002/diff/220001/base/threading/thread.h File base/threading/thread.h (right): https://codereview.chromium.org/2145463002/diff/220001/base/threading/thread.h#newcode44 base/threading/thread.h:44: // This API is not thread-safe: unless ...
4 years, 5 months ago (2016-07-22 18:18:59 UTC) #66
gab
https://codereview.chromium.org/2145463002/diff/220001/base/threading/thread.h File base/threading/thread.h (right): https://codereview.chromium.org/2145463002/diff/220001/base/threading/thread.h#newcode44 base/threading/thread.h:44: // This API is not thread-safe: unless indicated otherwise ...
4 years, 5 months ago (2016-07-22 18:28:12 UTC) #69
danakj
LGTM
4 years, 5 months ago (2016-07-22 18:52:24 UTC) #70
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2145463002/240001
4 years, 5 months ago (2016-07-22 19:03:51 UTC) #73
gab
On 2016/07/22 16:02:55, gab wrote: > Dana, all done, PTAnL, thanks! > > PS: Had ...
4 years, 5 months ago (2016-07-22 19:34:57 UTC) #74
commit-bot: I haz the power
Committed patchset #12 (id:240001)
4 years, 5 months ago (2016-07-22 21:27:08 UTC) #76
commit-bot: I haz the power
Patchset 12 (id:??) landed as https://crrev.com/1734a80f1519819eb6a3d8eb43064f8fb2c2e067 Cr-Commit-Position: refs/heads/master@{#407265}
4 years, 5 months ago (2016-07-22 21:29:03 UTC) #78
Wez
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc File base/threading/thread.cc (right): https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc#newcode140 base/threading/thread.cc:140: // |thread_lock_| is required... FWIW, this comment as worded ...
4 years, 5 months ago (2016-07-25 21:20:29 UTC) #80
Wez
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc File base/threading/thread.cc (right): https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc#newcode203 base/threading/thread.cc:203: DCHECK_EQ(id_, PlatformThread::CurrentId()); What is this DCHECK intended to protect ...
4 years, 5 months ago (2016-07-25 21:22:36 UTC) #81
gab
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc File base/threading/thread.cc (right): https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc#newcode140 base/threading/thread.cc:140: // |thread_lock_| is required... On 2016/07/25 21:20:29, Wez wrote: ...
4 years, 5 months ago (2016-07-26 02:48:23 UTC) #82
Wez
On 2016/07/26 02:48:23, gab wrote: > https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc > File base/threading/thread.cc (right): > > https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc#newcode140 > ...
4 years, 4 months ago (2016-07-26 17:32:54 UTC) #83
gab
On 2016/07/26 17:32:54, Wez wrote: > On 2016/07/26 02:48:23, gab wrote: > > > https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc ...
4 years, 4 months ago (2016-07-26 20:37:52 UTC) #84
danakj
4 years, 4 months ago (2016-07-26 20:44:32 UTC) #85
Message was sent while issue was closed.
On Tue, Jul 26, 2016 at 1:37 PM, <gab@chromium.org> wrote:

> On 2016/07/26 17:32:54, Wez wrote:
> > On 2016/07/26 02:48:23, gab wrote:
> > >
> >
>
>
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread.cc
> > > File base/threading/thread.cc (right):
> > >
> > >
> >
>
>
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread....
> > > base/threading/thread.cc:140: // |thread_lock_| is required...
> > > On 2016/07/25 21:20:29, Wez wrote:
> > > > FWIW, this comment as worded implies that callers were mis-using
> > > Start()/Stop()
> > > > in calling them from different Sequences, where AFAICT the issue is
> > actually
> > > > that you're specifically changing the API contract in this CL.
> > > >
> > > > It would be helpful to have the CL description and/or bug document
> why
> > > imposing
> > > > the same-Sequence restriction is preferable to the use of locks here.
> Right
> > > now
> > > > there's a cyclical reference between CL and bug rationale. :P
> > >
> > > Generally in Chromium, unless specified otherwise, classes are not to
> be
> > assumed
> > > as thread-safe.
> >
> > Yup, I'm not arguing with that. Just pointing out that your CL and bug
> > descriptions refer to one another as motivations for changes without
> providing
> > the motivation context.
>
> Right, thanks for pointing this out, hopefully with this discussion on both
> sides, it's now clarified :-).
>
> >
> > > The
> > > previous comment on Thread::StopSoon() makes this clear : "We should
> only be
> > > called on the same thread that started us.".
> >
> > Agreed; there was a change last year that added the unnecessary AutoLock
> in
> > Stop(), it seems.
> >
> > [snip]
> >
> > >
> >
>
>
https://codereview.chromium.org/2145463002/diff/240001/base/threading/thread....
> > > base/threading/thread.cc:203: DCHECK_EQ(id_,
> PlatformThread::CurrentId());
> > > On 2016/07/25 21:22:36, Wez wrote:
> > > > What is this DCHECK intended to protect against? Comment implies
> you're
> > > > concerned about sub-classes calling it on themselves..?
> > >
> > > As is often the case with DCHECKs, it's intended as documentation of
> the
> > > expected contract. Since every other method uses
> |owning_sequence_checker_|,
> I
> > > wanted to make it clear that it wasn't omitted here by accident but
> rather
> > > because this runs on the underlying thread, not on the owning sequence.
> >
> > That's true of public-facing APIs, but this one is [intended to be]
> called by
> > the Thread itself. Where there's a contract within an implementation
> (i.e. no
> > scope for callers breaking things) it's common to omit DCHECKs in the
> > implementation and validate that property via unit-tests.
>
> Sure, the DCHECK might not be very helpful to catch misuses, but I think it
> still helps readability for anyone grokking thread.cc without hindering
> anyone
> else that doesn't care, so why not?
>

I like it personally. Classes that deal with multiple threads, I like a
DCHECK and/or function name to say what thread for everything.

-- 
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.

Powered by Google App Engine
This is Rietveld 408576698