当前位置:网站首页>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 .
边栏推荐
- Why can't the database table be written into data
- Loss function: Diou loss handwriting implementation
- Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
- Simple understanding of the difference between get request and post submission
- More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
- Dart extended feature
- Prometheus 2.29.0 新特性
- visualstudio 和sql
- 我想问一下招商证券怎么开户?通过链接办理股票开户安全吗
- Comprehensively analyze the basic features and summary of free and paid SSH tools
猜你喜欢

单元测试效率优化:为什么要对程序进行测试?测试有什么好处?

【刷题篇】供暖器
![【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/70/8bf226964118efb324ca4d339df654.png)
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

DeFi“钱从哪来”?一个大多数人都没搞清楚的问题

【刷题篇】爱吃香蕉的珂珂

Apache Doris Compaction优化百科全书

可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈

Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation

重磅:国产IDE发布,由阿里研发,完全开源!

Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
随机推荐
“即服务”,企业数字化转型的必然选择
想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
数字时代,XDR(扩展检测与响应)的无限可能
How does MySQL merge columns?
数据库表为什么写不进数据了
可觀測,才可靠:雲上自動化運維CloudOps系列沙龍 第一彈
Read all the knowledge points about enterprise im in one article
[Title brushing] avoid flooding
【刷题篇】爱吃香蕉的珂珂
【刷题篇】供暖器
Defi "where does the money come from"? A problem that most people don't understand
第四批入围企业公示——年度TOP100智能网联供应商评选
目录相关命令
(8)JMeter元件详解之 Once only Controller 仅一次控制器
This editor will open source soon!
QQ 居然被盗了?原因在这......
Optimization of unit test efficiency: why test programs? What are the benefits of testing?
mysql拒绝访问、管理员身份打开的
Impersonate server and client using message queuing