Hello,
In the Go standard library, in the file log/slog/handler.go, I found the following code:
func (h *commonHandler) clone() *commonHandler {
// We can't use assignment because we can't copy the mutex.
return &commonHandler{
json: h.json,
opts: h.opts,
preformattedAttrs: slices.Clip(h.preformattedAttrs),
groupPrefix: h.groupPrefix,
groups: slices.Clip(h.groups),
nOpenGroups: h.nOpenGroups,
w: h.w,
mu: h.mu, // mutex shared among all clones of this handler
}
}
The first comment states that "we can't copy the mutex", but then the last line seems to copy the mutex anyway. What is going on here?
Maybe this just an oversight from a time when every hander had its own mutex? Or is there something subtle going on here?
Many thanks,
Jochen