mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-22 01:17:11 +08:00
37 lines
468 B
Go
37 lines
468 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func listing1() {
|
|
s := make([]int, 1)
|
|
|
|
go func() {
|
|
s1 := append(s, 1)
|
|
fmt.Println(s1)
|
|
}()
|
|
|
|
go func() {
|
|
s2 := append(s, 1)
|
|
fmt.Println(s2)
|
|
}()
|
|
}
|
|
|
|
func listing2() {
|
|
s := make([]int, 0, 1)
|
|
|
|
go func() {
|
|
sCopy := make([]int, len(s), cap(s))
|
|
copy(sCopy, s)
|
|
|
|
s1 := append(sCopy, 1)
|
|
fmt.Println(s1)
|
|
}()
|
|
|
|
go func() {
|
|
sCopy := make([]int, len(s), cap(s))
|
|
copy(sCopy, s)
|
|
|
|
s2 := append(sCopy, 1)
|
|
fmt.Println(s2)
|
|
}()
|
|
}
|