Permalink
Browse files

fix race around de.age. thank @shogo82148

  • Loading branch information...
Songmu committed Oct 29, 2017
1 parent e06ef5d commit 2801026fc3a1742d6140c79cc7c3b94114910b7d
Showing with 4 additions and 5 deletions.
  1. +4 −5 singleton/deeeet.go
View
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"sync"
"sync/atomic"
)
// Deeeeter implements Deeeet() method
@@ -13,7 +14,7 @@ type Deeeeter interface {
}
type deeeet struct {
age int
age int64
mu sync.RWMutex
}
@@ -32,10 +33,8 @@ func GetDeeeter() Deeeeter {
// Deeeet desu...
func (de *deeeet) Deeeet() {
de.mu.RLock()
de.age++
de.mu.RUnlock()
fmt.Printf("d%stです…\n", strings.Repeat("e", de.age))
age := int(atomic.AddInt64(&de.age, 1))
fmt.Printf("d%stです…\n", strings.Repeat("e", age))
}
func (de *deeeet) getAge() {

0 comments on commit 2801026

Please sign in to comment.