I'm not sure if this post fits here coz it's more about concurrency. I'm 
trying to reasoning if I could get by without atomic or other synchronization 
in this case.

So I have two go routines:

var sequence int64

// writer
for i := sequence; i < max; i++ {
  doSomethingWithSequence(i)
  sequence = i
}

// reader
for {
  doSomeOtherThingWithSequence(sequence)
}

And here're some potential risks I can think of:


   1. 
   
   reordering (for the writer, updating sequence happens before doSomething) 
   could happen, *but I can live with that.*
   2. 
   
   sequence is not properly aligned in memory so the reader might observe a 
   partially updated sequence. Running on (recent kernel) linux with 
   x86_64, can we rule that out?
   3. 
   
   go compiler 'cleverly optimizes' the reader, so the access to i never 
   goes to memory but 'stayed' in a register. Is that possible in go?
   4. 
   
   Anything else?
   
PS: I posted same thing on SO but people seem to be more focused on 
educating me about not going there, but that's really not my point. 

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/mechanical-sympathy/997dfab6-6a88-44f2-924f-9ebe0b2286c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to