当前位置:网站首页>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()
边栏推荐
- @Component与@Configuration区别
- When MySQL RDS is collected using Flink CDC, the datetime type field will be compared with the source table after collection
- Solid state storage manufacturer Yilian joins dragon dragon community to build a new open source ecosystem
- MySQL highly available cluster – MHA
- NVIDIA安装最新显卡驱动
- 2020版KALI安装教程
- High landing pressure of "authorization and consent"? Privacy computing provides a possible compliance "technical solution"
- I, a tester from a large factory, went to a state-owned enterprise with a 50% pay cut. I regret it
- Why does selenium become the first choice for web automated testing? (source code attached)
- [R language data science]: Text Mining (taking Trump's tweet data as an example)
猜你喜欢

0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解

Étalonnage de la caméra monoculaire et de la caméra binoculaire à l'aide de l'outil d'étalonnage kalibr

LSB hidden items of stream carrier based on assembly implementation

如何利用OpenMesh实现不同格式的3D文件间的转换

【 OpenGL 】 Random Talk 1. The camera rotates around a point in the space by dragging the mouse

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

研究所的这些优势真香!上岸率还极高!

@Difference between component and @configuration

最高81.98%!超百所“双一流”高校本科深造率公布

微信小程序开发储备知识
随机推荐
[R language data science]: Text Mining (taking Trump's tweet data as an example)
外部自动(PLC启动机器人)
About Kali using xshell connection
Review of mathematical knowledge: curve integral of type I
有遇到用flink-cdc采集MySQL-RDS的时候,datetime类型的字段,采集过来后和源表
解题元宇宙,网络游戏中的多元通信方案
0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解
正则表达式
NVIDIA安装最新显卡驱动
Summary of problems during xampp Apache installation
Redis bloom filter and cuckoo filter
AI and creativity
【Oracle】基础知识面试题
如何创建虚拟形象
使用kalibr标定工具进行单目相机和双目相机的标定
PHP delete directory
Information | Zuckerberg was rated as the most careless CEO in the global IT industry; China Mobile R & D tethered UAV emergency communication high altitude base station
疫情居家外包项目之协作开发| 社区征文
mysql数据库扫盲,你真的知道什么是数据库嘛
Kubernetes部署Dashboard(WEB UI管理界面)