The problem here is you are sending a copy of counter to the anonymous
function. You need to either not pass it and use the outer-scope counter
directly in the function, or pass a reference to the counter to the
function.

Hope this helps.

Le dim. 28 nov. 2021 à 16:19, Денис Мухортов <muhortovdeni...@gmail.com> a
écrit :

> Why are the values not incremented when declaring a structure with mutex
> in goroutines?
> https://go.dev/play/p/bPc1bg0AvJ4
>
> And what is the actual point in declaring something in anonymous
> functions, if in my experience it always works without it?
>
> --
> 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/7f3aaf03-0705-4e19-b027-68764b185b4dn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/7f3aaf03-0705-4e19-b027-68764b185b4dn%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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAL4P9zxPO6mdvAA8_LiTOaVK-iyWg5ZDLbfM1SB827twd%3DNH-A%40mail.gmail.com.

Reply via email to