当前位置:网站首页>Race of golang
Race of golang
2022-06-30 14:09:00 【Zhen Jie.】
because golang Medium go It's very convenient , Plus functions are very easy to hide go.
So a lot of times , When we write a program , We don't know if this program will have any problems in the case of concurrency .
So in essence ,goroutine The use of increases the risk factor of the function . For example, a Global or public variables , If it is not locked , Let's write down a relatively large project , I don't know if this variable will Cause multiple goroutine competition .
Take a look at the following example , Think about val Whether the variable needs to be locked ?
package main
import(
"fmt"
"time"
)
func main() {
val := 1
go func(){
val = 2
}()
val = 3
fmt.Println("val:",val)
for{
time.Sleep(time.Second)
}
}
result :
This command outputs Warning, Tell us ,goroutine7 Run to the The first 110 That's ok and main goroutine Run to the The first 112 That's ok It's time to trigger the competition .
and goroutine7 Is in The first 109 That's ok When it comes to .
Conclusion :go run - race *.go The command can help you check your code for missing locks , Competitive detection .
边栏推荐
- Inexplicable error occurred in unity's frequent switching branch result model
- DNS resolution home network access public DNS practice
- [observation] as the intelligent industry accelerates, why should AI computing power take the lead?
- More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
- [KALI] KALI系统、软件更新(附带镜像源)
- 这个编辑器即将开源!
- golang模板(text/template)
- 数字化转型道阻且长,如何迈好关键的第一步
- 【观察】智能产业加速,为何AI算力要先行?
- How to take the first step in digital transformation
猜你喜欢

Tencent two sides: @bean and @component are used on the same class. What happens?

MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
![【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

Multi terminal collaboration of Huawei accounts to create a better internet life

Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone

Optimization of unit test efficiency: why test programs? What are the benefits of testing?

科普达人丨漫画图解什么是eRDMA?

Unity animator parameter

Why does the folder appear open in another program

Mysql database foundation: stored procedures and functions
随机推荐
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
Flat shading with unity
Assertions of regular series
用Unity实现Flat Shading
Wuenda 2022 machine learning special course evaluation is coming!
Why does the folder appear open in another program
【系统分析师之路】第五章 复盘软件工程(软件过程改进)
想请教一下,我在佛山,到哪里开户比较好?手机开户是安全么?
[Title brushing] heater
单元测试效率优化:为什么要对程序进行测试?测试有什么好处?
半导体动态杂谈
幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
The programming competition is coming! B station surrounding, senior members and other good gifts to you!
华为帐号多端协同,打造美好互联生活
数字时代,XDR(扩展检测与响应)的无限可能
Apache Doris Compaction優化百科全書
More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
Golang template (text/template)
这个编辑器即将开源!
IM即时通讯应用开发中无法解决的“顽疾”