Re: [go-nuts] go vet not erroring waitgroup inc used after done

2024-03-25 Thread Ian Lance Taylor
On Mon, Mar 25, 2024 at 12:46 PM Nikhilesh Susarla
 wrote:
>
> Why isn't go vet complaining that wg.Add is happening after the usage. Where 
> as the document clearly says increment and then use it as the wg.Done may be 
> called an can run into negative/deadlock

First, please send Go code as plain text or as a link to the Go
playground.  The background on the text you sent makes it difficult to
read.  Thanks.

To answer your question, vet doesn't check for any possible error
condition.  As described at
https://cs.opensource.google/go/go/+/refs/tags/go1.22.1:src/cmd/vet/README,
vet checks for mistakes that are, among other things, common.   I'm
not sure the mistake you describe is common.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVjFsXnVjoTv_fyB7SYmwPrFhCg8su4hU-NGw5kS2YhFQ%40mail.gmail.com.


[go-nuts] go vet not erroring waitgroup inc used after done

2024-03-25 Thread Nikhilesh Susarla
Hello, 

// main.go
package main

import (
"sync"
"time"
)

func main() {
var wg sync.WaitGroup

go lolsleep(&wg)
wg.Add(1)

wg.Wait()
}

func lolsleep(wg *sync.WaitGroup) {
wg.Done()
time.Sleep(3 * time.Second)
}



go vet main.go

Why isn't go vet complaining that wg.Add is happening after the usage. 
Where as the document clearly says increment and then use it as the wg.Done 
may be called an can run into negative/deadlock

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/780d7c19-0141-425a-8ba5-ecc471efe97an%40googlegroups.com.