当前位置:网站首页>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 .
边栏推荐
- Directory related commands
- [scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)
- 想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
- "Persistent diseases" that cannot be solved in IM application development
- Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
- 一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
- golang模板(text/template)
- Implementation of forwarding server using IO multiplexing
- Numpy creates an empty array data = np empty(shape=[1, 64,64,3])
- More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
猜你喜欢
SQL attendance statistics monthly report
编程实战赛来啦!B站周边、高级会员等好礼送你啦!
我如何才能保护我的私钥?
Apache Doris Compaction优化百科全书
Rpm2rpm packaging steps
嵌入式开发:5个可能不再被禁止的C特征
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
QQ was stolen? The reason is
Introduction to reverse commissioning - VA and RVA conversion in PE 04/07
随机推荐
Why can't the database table be written into data
Jetpack compose for perfect screen fit
[scientific research data processing] [basic] category variable frequency analysis chart, numerical variable distribution chart and normality test (including lognormal)
优思学院:六西格玛不只是统计!
【系统分析师之路】第五章 复盘软件工程(软件过程改进)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
Chapter 13 signal (III) - example demonstration
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
"Persistent diseases" that cannot be solved in IM application development
Golang template (text/template)
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
损失函数:DIOU loss手写实现
Dart 扩展特性
IM即时通讯应用开发中无法解决的“顽疾”
Meaning of while (~scanf ("%d%d", & A, & B))
【刷题篇】避免洪水泛滥
SQL attendance statistics monthly report
With the development of industrial Internet, the landing and application of the Internet has become wider
How to execute a query SQL