Hi,


I have a problem that I have tried to reduce to a minimal re-producible 
example, I have not fully managed but it does show some to me strange 
behavior:


https://play.golang.org/p/ZCyumUPBos


I have a similar set up in a much larger set-up where I seem to see (no 
errors reported by race-detector) that sometimes inside a "actionWithState" 
the state is not remembered correctly/shared with other instances of 
"actionState"s. In this playground example however it always seems to 
behave as intended with each actionState's action method using its own 
state. In the example above however (I see the same thing) both actions *have 
the same address* when printed, how can that be that they behave 
differently if they point to the same data?


I.e. I have two questions where I would appreciate tips since I cannot seem 
to wrap my head around it:

 1. How can (in this code) actions[1] and actions[2] contain the same 
pointers (as seen by fmt.Print) yet behave differently when called as 
functions?

 2. Although the behavior of the example above is what I expected (apart 
from it printing the same pointer value), is there any circumstance under 
which they would start to "share state" which I have not thought of that 
could lead to the problem I am seeing in my larger code-base that you could 
think of?


Any thoughts appreciated :-)


-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to