Hi,

I would like to update a counter up to a certain limit atomically, without 
using a channel or mutex. What do you think of the following (equivalent) 
functions for sync/atomic?

func CompareAndInc(*addr, Max) bool {

  if *addr < Max {
    *addr++
    return true
  }
  return false
}

func CompareAndDec(*addr, Min) bool {

  if *addr > Min {
    *addr--
    return true
  }
  return false
}

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