diff options
author | Teddy Wing | 2023-05-18 15:34:25 +0200 |
---|---|---|
committer | Teddy Wing | 2023-05-18 15:34:25 +0200 |
commit | c80e0f9e939a9ade411b3926e84f97fa607fd09c (patch) | |
tree | ff9601023cc375b391a17dc0af6f223f0bc9ecea | |
parent | b87512b19fd60cee224b31c59eafe1e29f2580fd (diff) | |
download | gocapturedrefrace-c80e0f9e939a9ade411b3926e84f97fa607fd09c.tar.bz2 |
Add package documentation
-rw-r--r-- | capturedrefrace.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/capturedrefrace.go b/capturedrefrace.go index b58ed9d..e7d0c45 100644 --- a/capturedrefrace.go +++ b/capturedrefrace.go @@ -16,7 +16,38 @@ // along with Gocapturedrefrace. If not, see // <https://www.gnu.org/licenses/>. -// TODO: package documentation. +// Package capturedrefrace defines an Analyzer that checks for captured +// references in goroutine closures. +// +// # Analyzer capturedrefrace +// +// capturedrefrace: report captured variable references in goroutine +// closures. +// +// Goroutines that run function closures can capture reference variables from +// outer scopes which could lead to data races. This analyzer checks closures +// run by goroutines and reports uses of all variables declared in outer +// scopes, as well as arguments to the closure with a pointer type. +// +// For example: +// +// func (r *Record) CapturedReference() { +// capturedReference := 0 +// spline := &Spline{Curvature: 5.0} +// +// go func(s *Spline) { +// capturedReference += 1 // closure captures the variable +// // 'capturedReference' in a goroutine, which could +// // lead to data races +// +// if capturedReference > 0 { +// r.reticulateSplines() // goroutine closure captures 'r' +// } +// +// s.Curvature = 3.0 // 's' is a pointer type which could +// // lead to data races +// }(spline) +// } package capturedrefrace import ( |