On Wed, Oct 12, 2016 at 1:33 AM Minglangjun Li <[email protected]>
wrote:

> On Wed, Oct 12, 2016 at 11:53 AM, Jesse McNelis <[email protected]>
>  wrote:
>
> If you have multiple CPUs (and the Go memory model assumes that you
> always can) they won't even write updated values from their cache out
> to main memory until they hit a lock.
> The reading CPU has read a value from main memory and put it in it's
> cache, it assumes that value won't change in main memory unless it
> hits a lock of it's own.
>
> If you don't lock then both CPUs will just sit in their own little
> world updating and reading values in their own caches and are never
> aware of each other.
>
>
> Thanks Jesse. Good to know that.
>
> On Wed, Oct 12, 2016 at 3:26 PM, John Souvestre <[email protected]>
>  wrote:
>
> I see that others have already addressed the locking issued, but I noticed
> something else.  I don’t understand why you are using “select”.  With only
> one case, I think that it’s normally going to fail and exit the select
> block, then loop due to the “for”.  This will make it run constantly.
>
>
That's not true. One of the select cases has to be satisfied; there is no
failure. If there were a default case, that would be selected if no other
case is ready. Without a default case, the select will block until one of
the cases is ready. A single-case select can be replaced with a single send
statement or receiving into a variable.


> If you get rid of the “select” then the loop will block until something
> comes in from the channel.
>
>
>
> John
>
>     John Souvestre - New Orleans LA
>
>
> Please forgive me for that. I haven't been familiar with Go.
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

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

Reply via email to