Ian, thanks for the explanation and the link !

But I am still unclear how to implement such a concurrent counter in Go -
given that we can't find out what thread/cpu is the goroutine executing.
Note that in this case there was never the need of pinning a goroutine to a
thread or cpu; just that we wanted to know which is it, at any given moment
so as to access the required memory location.

Do you have any alternate ideas for this?

On Sun, Aug 14, 2016 at 10:18 PM, Ian Lance Taylor <i...@golang.org> wrote:

> On Sun, Aug 14, 2016 at 2:25 AM, gaurav <gauravagarw...@gmail.com> wrote:
> >
> > How do I get to know the Thread (or CpuCore) id on which the goroutine is
> > running?
>
> Go does not expose this information.  In Go it's also unreliable
> because the language makes no guarantees about when a goroutine may
> move from one thread, or CPU, to another.
>
> > In the get() call of this counter, I need to sum up array values; how
> does
> > one ensure that the  latest values written to the array are visible to
> the
> > goroutine calling the get() method? Are the values written using atomic
> > package made visible to all cores immediately? Or else, does
> > atomic.LoadInt32()guarantee to return the latest values? I think the
> problem
> > is that atomic package does not say anything about visibility of memory
> > updates across cores.
>
> The lack of documentation is https://golang.org/issue/5045.  It's not
> the case that values written are visible to all cores for ordinary
> memory access, but they are visible if you use atomic.LoadNN.  What is
> unclear is what that says about other memory writes, but I think the
> current implementation, and all plausible future implementations,
> treat Store as a store-release and treat Load as a load-acquire.
>
> Ian
>

-- 
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