当前位置:网站首页>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 .
边栏推荐
- Realize a simple LAN communication (similar to feiqiu)
- 重磅:国产IDE发布,由阿里研发,完全开源!
- 【观察】智能产业加速,为何AI算力要先行?
- numpy 创建空数组 data = np.empty(shape=[1, 64,64,3])
- navicat数据库建表是没有utf8选项。
- 随着产业互联网的发展,有关互联网的落地和应用也就变得宽阔了起来
- Meaning of while (~scanf ("%d%d", & A, & B))
- 提权扫描工具
- SQL attendance statistics monthly report
- SQL programming problem, test case failed
猜你喜欢

How can I protect my private key?

Rpm2rpm packaging steps

一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念

损失函数:DIOU loss手写实现

华为帐号多端协同,打造美好互联生活

嵌入式开发:5个可能不再被禁止的C特征

Mysql database foundation: stored procedures and functions

The programming competition is coming! B station surrounding, senior members and other good gifts to you!

香港回归20余年,图扑数字孪生港珠澳大桥,超震撼

MySQL access denied, opened as Administrator
随机推荐
华为帐号多端协同,打造美好互联生活
Wuenda 2022 machine learning special course evaluation is coming!
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
【Kubernetes系列】K8s设置MySQL8大小写不敏感
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
第四批入围企业公示——年度TOP100智能网联供应商评选
Talk about Vue's two terminal diff algorithm, analysis of the rendering principle of the mobile terminal, and whether the database primary key must be self incremented? What scenarios do not suggest s
【刷题篇】避免洪水泛滥
MySQL access denied, opened as Administrator
"Persistent diseases" that cannot be solved in IM application development
可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈
Prometheus 2.29.0 new features
Simple understanding of the difference between get request and post submission
半导体动态杂谈
Yousi College: Six Sigma is not just statistics!
Click the TD cell of table to open the dialog pop-up window. After obtaining the value, put the value back into the TD cell
Why can't the database table be written into data
Dart 扩展特性
Begin End use the pit encountered
Assertions of regular series