There can be a race condition in current TestForget, that said when
"close(secondCh)" is executed, the second goroutine will be finished
immediately, causing the third "g.Do" is evaluated.
To fix this, we change to use "g.DoChan" for both second and third. In
second, we block to make sure it's still running at the time we call
third. after then we unblock second and verify the result.
Fixesgolang/go#42092
Change-Id: I980fdf109a531e2b7a74c8149b4fcaa338775e08
Reviewed-on: https://go-review.googlesource.com/c/sync/+/263877
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
The js port does not yet support os/exec.
Updates golang/go#37100
Updates golang/go#33519
Change-Id: I9608b7febfdc274dc1b9f34a92d00ef7bea4e13c
Reviewed-on: https://go-review.googlesource.com/c/sync/+/260717
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
When first Do panic, the related wait group will never be done,
and all the subsequent calls would block on the same wait group forever.
Fixesgolang/go#41133
Change-Id: I0ad9bfb387b6133b10766a34fc0040f200eae27e
Reviewed-on: https://go-review.googlesource.com/c/sync/+/251677
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Ian Lance Taylor <iant@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
When `Release`, if the remaining tokens are not enough for the front waiter, no waiters will be notified.
So if the canceled waiter is the front one, it should try to notify following waiters if there are remaining tokens.
I found this bug when implementing a cancelable rwmutex based on semaphore:
https://github.com/zhiqiangxu/util/blob/master/mutex/crwmutex.go
This bug can be verified by this test:
https://github.com/zhiqiangxu/util/blob/master/mutex/crwmutex_test.go#L43
Change-Id: Id8564976bd375a82c4fbc6cb08b0bb83118a346c
GitHub-Last-Rev: 29b6ff26bf779d23239cfe64a395378a9e41d1fc
GitHub-Pull-Request: golang/sync#10
Reviewed-on: https://go-review.googlesource.com/c/sync/+/223418
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
sync.Map was introduced in Go 1.9, this change updates the syncmap package to use a type alias
to sync.Map for 1.9 and later. It also updates the comments to reflect this change.
Fixesgolang/go#33867
Change-Id: Ia58ad2bc409f8fcb8a7539ef165148315da5cfb1
Reviewed-on: https://go-review.googlesource.com/c/sync/+/192737
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
When Forget was called, we delete key associated with current call from
map. When that call is done, it does delete key again, causing the same
key set by other call after Forget lost.
To fix it, adding a boolean value to check whether the call is forgotten,
the call only does delete key if Forget is not called.
Fixesgolang/go#31420
Change-Id: I9708352ca3ff76c77f659916b37a496fdeb480d2
Reviewed-on: https://go-review.googlesource.com/c/sync/+/171897
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change adds a go.mod file to this repo, following the
requirements stated in bcmills's comment here:
https://golang.org/issue/28136#issuecomment-462971974. It's
important to note that we will not be
adding versions to the repo for now.
This change does not add a go.sum because this repo has no dependencies.
The change was generated by running "go mod init" and "go mod tidy" using Go
1.11.5 in the top-level directory of the repository.
Updates golang/go#28136
Change-Id: Ie4f1270a0dfefd4239badf86daa0d7a5b17fd0d5
Reviewed-on: https://go-review.googlesource.com/c/162823
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Updates golang/go#24185
Change-Id: I892f30f02f9ae40554790e9c177cb79d193bffd5
Reviewed-on: https://go-review.googlesource.com/100696
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
I've commented several times in various forums that basically every
time I've seen the “worker goroutine” pattern in Go, there has turned
out to be a cleaner implementation using semaphores.
This change adds a simple such example. (For more complex usage, I
would generally pair the semaphore with an errgroup.Group.)
Change-Id: Ibf69ee761d14ba59c1acc6a2d595b4fcf0d8f6d6
Reviewed-on: https://go-review.googlesource.com/75170
Reviewed-by: Ross Light <light@google.com>
Move the README to README.md so Gerrit can render it; currently
Gerrit only renders files named exactly "README.md" (for example at
https://go.googlesource.com/go).
Add more links to the README explaining how to file issues,
how to submit code changes, where to download the code to and
how to get it. Hopefully this should help people who go to
https://go.googlesource.com/sync or https://github.com/golang/sync
figure out how to get started with development.
Change-Id: Iafdbec407bd6f61459aabe6e2c4703132d038b69
Reviewed-on: https://go-review.googlesource.com/49872
Reviewed-by: Kevin Burke <kev@inburke.com>
TestWeighted's runtime was roughly proportional to the number of CPUs,
so it ran a long time on PPCs (160 CPUs).
Make the number of loops in the test an inverse function of the number
of CPUs, to keep the test short.
Change-Id: Id853dbb5e5e2f9fb95966d19ef0c511e3f8080e0
Reviewed-on: https://go-review.googlesource.com/43632
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The mainline syncmap.Map has allowed mutations within Range callbacks
since https://golang.org/cl/37342. The reference
implementations used in map_bench_test need to do the same.
Change-Id: Id73d254fa01cc64a1f00eb1903488796e1282423
Reviewed-on: https://go-review.googlesource.com/42956
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This package provides a weighted semaphore that is context-aware.
The code is derived from a similar package inside Google.
Change-Id: Id1dad96d79e8ccfd289e4299e8265aa5bdad3a5b
Reviewed-on: https://go-review.googlesource.com/38298
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Add a test for Range with concurrent Loads and Stores.
The previous quick-check tests generated long, mostly-non-ASCII
strings that were hard to debug on failure; this change makes the keys
and values short and human-readable, which also tends to produce more
key collisions in the test as a side-effect.
updates golang/go#18177
Change-Id: Ie56a64ec9fe295435682b90c3e6466ed5b349bf9
Reviewed-on: https://go-review.googlesource.com/37150
Reviewed-by: Russ Cox <rsc@golang.org>
This makes git-codereview review issue references
to refer to the main Go repo.
Change-Id: I17003885f15358f776a475a76a31dac179de9676
Reviewed-on: https://go-review.googlesource.com/33908
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Package errgroup provides synchronization, error propagation, and
Context cancellation for groups of goroutines working on subtasks of a
common task.
Change-Id: Ic9e51f6f846124076bbff9d53b0f09dc7fc5f2f0
Reviewed-on: https://go-review.googlesource.com/24894
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>