The mutex field of the common handler struct became a pointer-to-mutex at some 
point IIRC - it is currently, so copying should be fine.

Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: golang-nuts@googlegroups.com <golang-nuts@googlegroups.com> on behalf of 
Eli Lindsey <e...@siliconsprawl.com>
Sent: Friday, May 24, 2024 7:18:51 AM
To: Jochen Voss <jochen.v...@gmail.com>
Cc: golang-nuts <golang-nuts@googlegroups.com>
Subject: Re: [go-nuts] mutex in slog/handler.go?

Git blame may be helpful, and specifically commit 847d40d6998. It looks like 
code drifted from the comment.

-eli

On May 24, 2024, at 9:25 AM, Jochen Voss <jochen.v...@gmail.com> wrote:

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


--
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<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/153e9898-f17e-44cc-ab2a-8570f916c0c3n%40googlegroups.com<https://groups.google.com/d/msgid/golang-nuts/153e9898-f17e-44cc-ab2a-8570f916c0c3n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/D370602F-6226-4AAC-B3EC-6BA164FEA4F9%40siliconsprawl.com<https://groups.google.com/d/msgid/golang-nuts/D370602F-6226-4AAC-B3EC-6BA164FEA4F9%40siliconsprawl.com?utm_medium=email&utm_source=footer>.

-- 
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/SJ0PR07MB97958715C77D9CCFC2C2C1CFA0F52%40SJ0PR07MB9795.namprd07.prod.outlook.com.

Reply via email to