Skip to content

Commit d7a4061

Browse files
authored
(minor): update mutexes example to use wg.Go instead of manual creation (#623)
* (minor): update mutexes example to use wg.Go instead of manual creation * Create an output Fixes #622 --------- Co-authored-by: Gala <dawo9889>
1 parent 7fe5e6e commit d7a4061

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

examples/mutexes/mutexes.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ func main() {
4545
for range n {
4646
c.inc(name)
4747
}
48-
wg.Done()
4948
}
5049

5150
// Run several goroutines concurrently; note
5251
// that they all access the same `Container`,
5352
// and two of them access the same counter.
54-
wg.Add(3)
55-
go doIncrement("a", 10000)
56-
go doIncrement("a", 10000)
57-
go doIncrement("b", 10000)
53+
wg.Go(func() {
54+
doIncrement("a", 10000)
55+
})
56+
57+
wg.Go(func() {
58+
doIncrement("a", 10000)
59+
})
60+
61+
wg.Go(func() {
62+
doIncrement("b", 10000)
63+
})
5864

5965
// Wait for the goroutines to finish
6066
wg.Wait()

examples/mutexes/mutexes.hash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1c56c75162419ced8437b7ebe53ee65e5479f645
2-
CawzyQnvH6W
1+
5271a346794ed097df21fb0f2b2d3d01c9bb361c
2+
u0VAVSWRlU0

public/mutexes

Lines changed: 29 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)