On Friday, February 16, 2018 at 3:27:04 PM UTC+2, dc0d wrote:
>
> Why sync.Once uses a sync.Mutex in addition to atomic functions?
>
> What are the drawbacks/shortcomings/deficiencies of this implementation?
>
> type Once struct {
> done uint32
> }
>
>
> func (o *Once) Do(f func()) {
> if !atomic.CompareAndSwapUint32(&o.done, 0, 1) {
> return
> }
> f()
> }
>
>
You implementation returns immediately, if f() is still running, while in
original implementation all concurrent calls to Do() returns when f()
return.
Djadala
--
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.