Some of our code uses something like:

type Dummy struct {
closed int64
}

func(d *Dummy) IsClosed() bool {
return atomic.LoadInt64(&d.closed) == 1
}

func(d *Dummy) Close() error {
if !atomic.CompareAndSwapInt64(&d.closed, 0, 1) {
return fmt.Errorf("already closed")
}
// other logic
return nil
}

IsClosed feels racy to me, is it better to use atomic.CompareAndSwap(&d.closed, 
1, 1) for IsClosed?


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