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
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
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 :
>
Some people put all their variable declarations at the beginning of a
function.
Others put them at various places in a function, where the variables are
used.
I've always wondered if a variable declaration results in any runtime
overhead.
One obvious concern is what happens if a variable declar
I'm trying to transfer arbitrary structs over gRPC. To achieve this I've
trying to use gob for encoding the interface{} part of the structs. The
code looks somewhat like https://go.dev/play/p/4Q5CQE4Wcy2 but not entirely.
Two things strike me strange:
- I receive "gob: decoding into local type [
In K&R C back in the 1970s, you had to declare your local variables at the
beginning of a function, before any statements.
I think this is the source of the habit of declaring your variables first.
Readability is key here. So it makes sense to declare a statement close to
where it is first used,
On Sun, Nov 28, 2021 at 3:09 PM Amnon wrote:
>
> In K&R C back in the 1970s, you had to declare your local variables at the
> beginning of a function, before any statements.
> I think this is the source of the habit of declaring your variables first.
>
> Readability is key here. So it makes sense
On Sat, Nov 27, 2021 at 3:53 PM David Karr wrote:
>
> On Saturday, November 27, 2021 at 1:13:12 PM UTC-8 David Karr wrote:
>>
>> On Sat, Nov 27, 2021 at 11:57 AM Ian Lance Taylor wrote:
>>>
>>> On Sat, Nov 27, 2021 at 11:01 AM David Karr wrote:
>>> >
>>> > I'm aware of the "build constraints" me