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, Денис Мухортов a
écrit :
>
On Sun, Nov 28, 2021 at 4:19 PM Денис Мухортов
wrote:
> Why are the values not incremented when declaring a structure with mutex
> in goroutines?
> https://go.dev/play/p/bPc1bg0AvJ4
>
You have multiple problems:
1. You are passing `counter` to the goroutine as a value, making a copy
2. You have
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 sub