A1B2C3
用兩個 go routine 印出 A1B2C3....Z26 Two Go Routine Print A1B2C3....Z26
Channle With Buffer
func ChannelWBuffer() {
abc := make(chan struct{}, 1)
num := make(chan struct{}, 1)
done := make(chan struct{})
abc
Channel Without Buffer
func ChannelWOBuffer() {
abc := make(chan struct{})
num := make(chan struct{})
done := make(chan struct{})
go func() {
for i := 65; i
Wait Group
func WGLock() {
abcMux := sync.Mutex{}
numMux := sync.Mutex{}
numMux.Lock()
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
defer wg.Done()
for i := 65; i
Benchmark
goos: darwin
goarch: amd64
pkg: LeetcodeGolang/Algorithms/A1B2C3
cpu: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz
BenchmarkChannelWBuffer-4 79159 14612 ns/op 344 B/op 5 allocs/op
BenchmarkChannelWOBuffer-4 83068 14451 ns/op 344 B/op 5 allocs/op
BenchmarkWGLock-4 51303 23072 ns/op 96 B/op 5 allocs/op
PASS
ok LeetcodeGolang/Algorithms/A1B2C3 4.092s