Skip to content

Commit

Permalink
cmd/go: fix data race in TestScript
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie committed Aug 14, 2022
1 parent 2f6783c commit 13faa5c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cmd/go/internal/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,23 @@ func (c *Command) Runnable() bool {
return c.Run != nil
}

var atExitFuncs []func()
var (
atExitFuncsLock sync.Mutex
atExitFuncs []func()
)

func AtExit(f func()) {
atExitFuncsLock.Lock()
defer atExitFuncsLock.Unlock()
atExitFuncs = append(atExitFuncs, f)
}

func Exit() {
atExitFuncsLock.Lock()
for _, f := range atExitFuncs {
f()
}
atExitFuncsLock.Unlock()
os.Exit(exitStatus)
}

Expand Down

0 comments on commit 13faa5c

Please sign in to comment.