重写多协程问题
This commit is contained in:
19
test/Consumer.go
Normal file
19
test/Consumer.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func GoConsumer(mx *sync.Mutex, ch chan int) {
|
||||
defer mx.Unlock()
|
||||
|
||||
for {
|
||||
select {
|
||||
case v := <-ch:
|
||||
mx.Lock()
|
||||
fmt.Println("读取到", v)
|
||||
mx.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user