61 Star 659 Fork 311

ShirDon-廖显东/Go Web编程实战派源码

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
channel1.go 801 Bytes
Copy Edit Raw Blame History
ShirDon-廖显东 authored 2021-01-19 21:02 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go Web编程实战派从入门到精通》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 仓库地址:https://gitee.com/shirdonl/goWebActualCombat
// 仓库地址:https://github.com/shirdonl/goWebActualCombat
//++++++++++++++++++++++++++++++++++++++++
package main
import (
"fmt"
"runtime"
"sync"
)
var Counter int
func Count(lock *sync.Mutex) {
lock.Lock() // 上锁
Counter++
fmt.Println("Counter =", Counter)
lock.Unlock() // 解锁
}
func main() {
lock := &sync.Mutex{}
for i := 0; i < 6; i++ {
go Count(lock)
}
for {
lock.Lock() // 上锁
c := Counter
lock.Unlock() // 解锁
runtime.Gosched() // 出让时间片
if c >= 6 {
break
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goWebActualCombat.git
git@gitee.com:shirdonl/goWebActualCombat.git
shirdonl
goWebActualCombat
Go Web编程实战派源码
11434bb9048a

Search