Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(91)

Issue 85580043: code review 85580043: sync: fix spurious wakeup from WaitGroup.Wait (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by ruiu
Modified:
11 years, 1 month ago
Reviewers:
gobot, brainman, rsc, dvyukov, ioe
CC:
dvyukov, 0xjnml, rsc, golang-codereviews
Visibility:
Public.

Description

sync: fix spurious wakeup from WaitGroup.Wait There is a race condition that causes spurious wakeup from Wait in the following case: G1: decrement wg.counter, observe the counter is now 0 (should unblock goroutines queued *at this moment*) G2: increment wg.counter G2: call Wait() to add itself to the wait queue G1: acquire wg.m, unblock all waiting goroutines In the last step G2 is spuriously woken up by G1. Fixes issue 7734.

Patch Set 1 #

Patch Set 2 : diff -r 519230b4d06a https://code.google.com/p/go #

Patch Set 3 : diff -r 519230b4d06a https://code.google.com/p/go #

Patch Set 4 : diff -r 519230b4d06a https://code.google.com/p/go #

Patch Set 5 : diff -r 519230b4d06a https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+32 lines, -4 lines) Patch
M src/pkg/sync/waitgroup.go View 1 1 chunk +6 lines, -4 lines 0 comments Download
M src/pkg/sync/waitgroup_test.go View 1 2 3 2 chunks +26 lines, -0 lines 0 comments Download

Messages

Total messages: 30
ruiu
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
11 years, 1 month ago (2014-04-08 19:47:54 UTC) #1
rsc
R=dvyukov It seems to me that this code replaces a spurious wakeup with a missed ...
11 years, 1 month ago (2014-04-08 20:32:21 UTC) #2
ruiu
I don't think that should be considered as a missed wakeup, because the order of ...
11 years, 1 month ago (2014-04-08 20:47:13 UTC) #3
dvyukov
ouch! great job! how have you found this? preliminary the fix looks correct
11 years, 1 month ago (2014-04-09 07:34:47 UTC) #4
dvyukov
On 2014/04/08 20:47:13, ruiu wrote: > I don't think that should be considered as a ...
11 years, 1 month ago (2014-04-09 07:36:19 UTC) #5
dvyukov
please add the test to waitgroup_test.go use the program that you provided in the issue ...
11 years, 1 month ago (2014-04-09 07:37:58 UTC) #6
ruiu
I found it by reading the code of WaitGroup. I have also read all the ...
11 years, 1 month ago (2014-04-09 08:03:25 UTC) #7
dvyukov
On Wed, Apr 9, 2014 at 12:03 PM, <ruiu@google.com> wrote: > I found it by ...
11 years, 1 month ago (2014-04-09 08:09:28 UTC) #8
rsc
On Wed, Apr 9, 2014 at 3:36 AM, <dvyukov@google.com> wrote: > On 2014/04/08 20:47:13, ruiu ...
11 years, 1 month ago (2014-04-09 13:41:26 UTC) #9
0xjnml
On Wed, Apr 9, 2014 at 3:41 PM, Russ Cox <rsc@golang.org> wrote: > Are you ...
11 years, 1 month ago (2014-04-09 13:50:40 UTC) #10
rsc
On Wed, Apr 9, 2014 at 9:50 AM, Jan Mercl <0xjnml@gmail.com> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 14:00:52 UTC) #11
dvyukov
On Wed, Apr 9, 2014 at 6:41 AM, Russ Cox <rsc@golang.org> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 14:03:35 UTC) #12
rsc
On Wed, Apr 9, 2014 at 10:03 AM, Dmitry Vyukov <dvyukov@google.com> wrote: > Add of ...
11 years, 1 month ago (2014-04-09 14:08:19 UTC) #13
dvyukov
On Wed, Apr 9, 2014 at 7:08 AM, Russ Cox <rsc@golang.org> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 14:16:22 UTC) #14
rsc
On Wed, Apr 9, 2014 at 10:16 AM, Dmitry Vyukov <dvyukov@google.com> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 14:33:29 UTC) #15
dvyukov
On Wed, Apr 9, 2014 at 7:33 AM, Russ Cox <rsc@golang.org> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 14:44:50 UTC) #16
rsc
On Wed, Apr 9, 2014 at 10:44 AM, Dmitry Vyukov <dvyukov@google.com> wrote: > >> Do ...
11 years, 1 month ago (2014-04-09 16:31:41 UTC) #17
ruiu
On Wed, Apr 9, 2014 at 9:31 AM, Russ Cox <rsc@golang.org> wrote: > On Wed, ...
11 years, 1 month ago (2014-04-09 18:02:10 UTC) #18
rsc
ruiu, please add the test so we can submit this CL. thanks.
11 years, 1 month ago (2014-04-09 19:17:25 UTC) #19
ruiu
Hello dvyukov@google.com, 0xjnml@gmail.com (cc: golang-codereviews@googlegroups.com, rsc@golang.org), Please take another look.
11 years, 1 month ago (2014-04-09 19:44:21 UTC) #20
rsc
LGTM leaving for dvyukov
11 years, 1 month ago (2014-04-09 19:54:52 UTC) #21
ruiu
Dmitry, I don't have commit access, so please submit if it's LGTM. Thanks. On Wed, ...
11 years, 1 month ago (2014-04-09 19:57:31 UTC) #22
dvyukov
LGTM
11 years, 1 month ago (2014-04-10 14:44:35 UTC) #23
dvyukov
*** Submitted as https://code.google.com/p/go/source/detail?r=e95997ba7135 *** sync: fix spurious wakeup from WaitGroup.Wait There is a race ...
11 years, 1 month ago (2014-04-10 14:44:50 UTC) #24
gobot
This CL appears to have broken the windows-amd64-race builder. See http://build.golang.org/log/2739e5425f33ec233427501024b763e7309ee182
11 years, 1 month ago (2014-04-10 14:49:13 UTC) #25
dvyukov
Looks unrelated: --- FAIL: TestCtrlBreak (0.55 seconds) signal_windows_test.go:73: Failed to compile: exit status 2 # ...
11 years, 1 month ago (2014-04-10 14:51:28 UTC) #26
brainman
On 2014/04/10 14:51:28, dvyukov wrote: > Looks unrelated: > > --- FAIL: TestCtrlBreak (0.55 seconds) ...
11 years, 1 month ago (2014-04-11 06:42:12 UTC) #27
dvyukov
On Fri, Apr 11, 2014 at 10:42 AM, <alex.brainman@gmail.com> wrote: > On 2014/04/10 14:51:28, dvyukov ...
11 years, 1 month ago (2014-04-11 07:34:59 UTC) #28
brainman
On 2014/04/11 07:34:59, dvyukov wrote: > > I've connected to the builder and it has ...
11 years, 1 month ago (2014-04-11 07:46:21 UTC) #29
ioe
11 years, 1 month ago (2014-04-12 21:59:46 UTC) #30
On Wednesday, April 9, 2014 6:31:40 PM UTC+2, russ cox wrote:
> I think it is important that Wait and Add behave as if some ordering happened:
either Wait before Add, or Wait after Add, and either way Wait does not block
forever. I don't think that should be controversial, and I don't think it needs
to be called out in any documentation either. 

Thanks for clearing this up! 

I always considered the sequence Wait();Add() as invalid and considered the
sync.WaitGroup as consumable resource, which is consumed after the call to Wait.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b