On Wed, Oct 12, 2016 at 1:26 PM,  <[email protected]> wrote:
> These are the only two places that access commitIndex. I didn't acquire the
> lock when reading commitIndex since I think its OK to read a stale value in
> my case.

Remember that locking is communication.
Saying, "I never poll the http server, it's ok if I have a stale
value" is silly if you're expecting to know if that value on the
server ever changes.

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.

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