Indeed this is what I do but I learned the hard way and often it comes up
as "safe" in the mailing list to not do so but while true from a memory
model perspective it is, I would say, wrong to do so.
mån 6 nov. 2017 kl 10:39 skrev Christoph Berger <
christoph.g.ber...@gmail.com>:
> Always call
Just a note that waitGroup should be passed as reference to
functions/methods rather than as value. I have made mistakes where the
program hung as Done was called on copy of waitgroup rather than on the
original wg to which tasks were added.
Here it is not a problem as waitgroup used within
Always call Add() before spawning the corresponding goroutine(s). And
always call Add() in the same goroutine that also calls Wait(). This way
you have no race condition between Add(), Done(), and Wait().
On Saturday, November 4, 2017 at 10:46:21 AM UTC+1, Henrik Johansson wrote:
>
> I find
] On
Behalf Of Henrik Johansson
Sent: 2017 November 04, Sat 04:46
To: 2891132l...@gmail.com
Cc: golang-nuts
Subject: Re: [go-nuts] Re: concurrency programing about go
I find continuously adding and calling done on a waitgroup a bit odd. The
waiting goroutine can continue as soon as the count
I find continuously adding and calling done on a waitgroup a bit odd. The
waiting goroutine can continue as soon as the count is zero so there is a
race between adds and dones.
On Sat, 4 Nov 2017, 10:01 , <2891132l...@gmail.com> wrote:
> Thank you very much.Sorry I still have some
Thank you very much.Sorry I still have some question:what's the function of
wg? what does the sentense "wg.Add(2) " mean?? I found that if I change 2
into 1,the result is differnet.
在 2017年11月3日星期五 UTC+8上午4:45:47,snmed写道:
>
> Hi
>
> Here is the code:
>
> Version 1:
> package main
>
> import (
Hi
Here is the code:
Version 1:
package main
import (
"fmt"
"sync"
)
var a string
var once sync.Once
func setup() {
a = "hello,world\n"
}
func doprint() {
once.Do(setup)
fmt.Print(a)
}
func twoprint() <-chan struct{} {
var wg sync.WaitGroup
wg.Add(2)
ch := make(chan struct{})
go func() {
Sorry,I try my best to open the website but it can't work.Can you write it
??Thank you so much.
在 2017年10月30日星期一 UTC+8下午4:29:44,snmed写道:
>
> Hi
>
> There are several ways to solve it, here are two of them:
>
> https://play.golang.org/p/wJwkI7HQwv
> https://play.golang.org/p/nasUcgBeG4
>
> I
Hi
There are several ways to solve it, here are two of them:
https://play.golang.org/p/wJwkI7HQwv
https://play.golang.org/p/nasUcgBeG4
I prefer the first one, because so I can decide if i want to wait for the
end of twoprint or not.
Cheers
Am Montag, 30. Oktober 2017 06:43:45 UTC+1 schrieb
Yes, you're right.So how to solve it??
在 2017年10月30日星期一 UTC+8下午12:37:49,Dave Cheney写道:
>
> Hello. I’m guessing that your tried calling twoprint(), but you’ve
> probably found that nothing is printed to the screen before your program
> exits.
>
> Is that correct?
--
You received this message
10 matches
Mail list logo