当前位置:网站首页>Go语言多方式并发实现龟兔赛跑
Go语言多方式并发实现龟兔赛跑
2022-06-29 17:12:00 【_七里香】
在代码的海洋里遨游,七八十来种都可以写出来,这里先贴三种吧。
如有帮助,欢迎收藏哦!
背景
模拟龟兔赛跑
各自以各自速度跑,假设兔子一次跑1.1米,乌龟一次跑0.2米;
统一开始计时,最终两人全部跑完才能算比赛结束。
目录
姿势1
采用WaitGroup
func main() {
var (
Total float64 = 5 // 由于乌龟跑的慢不太便于观察打印,因此改小一点
RabbitAdd = 1.1
TurtleAdd = 0.2
)
start := time.Now().UnixNano()
wg := sync.WaitGroup{}
wg.Add(1)
// 兔子
go func() {
defer wg.Done()
边栏推荐
- C语言微博用户管理系统
- 使用kalibr標定工具進行單目相機和雙目相機的標定
- About harbor private warehouse forgetting the login password
- 基于深度学习的Wiki中文语料词word2vec向量模型
- What are the advantages of SaaS services
- Which is better and safer, GF e-gold or Dongfang fortune
- c# 国内外ORM 框架 dapper efcore sqlsugar freesql hisql sqlserver数据常规插入测试性能对比
- C language microblog user management system
- InheritableThreadLocal 在线程池中进行父子线程间消息传递出现消息丢失的解析
- KUKA子程序/函数怎么建立和使用方法
猜你喜欢

可转债策略之---(摊饼玩法,溢价玩法,强赎玩法,下修玩法,双低玩法)

I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it

@Difference between component and @configuration

Problem solving metauniverse, multi communication scheme in online games

How to use openmesh to realize the conversion between 3D files of different formats

LSB hidden items of stream carrier based on assembly implementation

【南京大学】考研初试复试资料分享

PCB板框的绘制——AD19

Inheritablethreadlocal resolves message loss during message transmission between parent and child threads in the thread pool

机器学习7-支持向量机
随机推荐
Practice | extreme optimization of script errors - make script errors clear at a glance
6.25atcoderabc257e - addition and multiplication 2
我的远程办公初体验 | 社区征文
Advanced webgl performance optimization
Kubernetes deployment dashboard (Web UI management interface)
Review of mathematical knowledge: curve integral of type I
New feature of C11 - Auto and decltype type type indicators
Graduates are confused and middle-aged people are anxious. How can the career path become wider and wider?
Calibration of monocular camera and binocular camera with kalibr calibration tool
XAMPP Apache安装时问题总结
iNFTnews | Meta在元宇宙中的后续计划会是什么?
卷妹带你学jdbc—2天冲刺Day1
LSB hidden items of stream carrier based on assembly implementation
SLAM中的子图
mysql数据库扫盲,你真的知道什么是数据库嘛
What are the Commonwealth countries
What are the project management systems suitable for small and medium-sized enterprises?
KUKA robot external axis configuration what you must know
C language microblog user management system
6.26CF模拟赛D:黑白条题题解