Re: [go-nuts] sync/atomic suggestion

2019-02-27 Thread Ian Lance Taylor
On Wed, Feb 27, 2019 at 12:46 PM Serhat Şevki Dinçer wrote: > > 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

[go-nuts] sync/atomic suggestion

2019-02-27 Thread Serhat Şevki Dinçer
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