waitgroup

package
v0.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2025 License: BSD-3-Clause Imports: 10 Imported by: 3

Documentation

Overview

Package waitgroup defines an Analyzer that detects simple misuses of sync.WaitGroup.

Analyzer waitgroup

waitgroup: check for misuses of sync.WaitGroup

This analyzer detects mistaken calls to the (*sync.WaitGroup).Add method from inside a new goroutine, causing Add to race with Wait:

// WRONG
var wg sync.WaitGroup
go func() {
        wg.Add(1) // "WaitGroup.Add called from inside new goroutine"
        defer wg.Done()
        ...
}()
wg.Wait() // (may return prematurely before new goroutine starts)

The correct code calls Add before starting the goroutine:

// RIGHT
var wg sync.WaitGroup
wg.Add(1)
go func() {
	defer wg.Done()
	...
}()
wg.Wait()

Package waitgroup defines an Analyzer that detects simple misuses of sync.WaitGroup.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "waitgroup",
	Doc:      analysisutil.MustExtractDoc(doc, "waitgroup"),
	URL:      "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/waitgroup",
	Requires: []*analysis.Analyzer{inspect.Analyzer},
	Run:      run,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL