Created
January 18, 2014 03:16
-
-
Save codeskyblue/8485670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
) | |
type Record struct { | |
a int | |
b int | |
c int | |
} | |
var ( | |
m = make(map[string]Record) | |
v1 = Record{1, 2, 3} | |
v2 = Record{4, 5, 6} | |
empty = Record{0, 0, 0} | |
) | |
func Check(m map[string]Record) { | |
x := m["a"] | |
if x != v1 && x != v2 && x != empty { | |
log.Fatal("but got expected", x) | |
} | |
} | |
func main() { | |
fmt.Println("Hello world") | |
m["a"] = v1 | |
go func() { | |
for { | |
m["a"] = v2 | |
Check(m) | |
} | |
}() | |
go func() { | |
for { | |
m["a"] = v1 | |
Check(m) | |
} | |
}() | |
go func() { | |
for { | |
delete(m, "a") | |
m["a"] = v1 | |
Check(m) | |
} | |
}() | |
for { | |
time.Sleep(time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
when call delete function, other go routine may got nil of m