当前位置:网站首页>Go synchronization waiting group
Go synchronization waiting group
2022-06-25 02:40:00 【Pumpkin head 777】
Go In addition to using channels in language (channel) And mutex for synchronization between two concurrent programs , You can also use wait groups to synchronize multiple tasks , Waiting group can ensure that a specified number of tasks can be completed in a concurrent environment
stay sync.WaitGroup( Waiting group ) Type in the , Every sync.WaitGroup Value internally maintains a count , The initial default value for this count is zero .
package main
import (
"fmt"
"sync"
"time"
)
var wg sync.WaitGroup // Define a synchronization waiting group
func task(i int) {
fmt.Println("task...", i)
// Time consuming operational tasks , Network request , Read the file
time.Sleep(time.Second)
wg.Done() // Subtract a count
}
func main() {
for i := 0; i < 10; i++ {
wg.Add(1) // Add a count
go task(i)
}
wg.Wait() // Block until all tasks are completed
fmt.Println("over")
}
边栏推荐
- Four characteristics of actual attack and defense drill
- 指南针靠谱吗?开证券账户安全吗?
- Internship: use of SVN
- psql 列转行
- Resolution of cross reference in IDA
- Are programmers from Huawei, Alibaba and other large manufacturers really easy to find?
- Please run IDA with elevated permissons for local debugging.
- I've been doing software testing for two years. I'd like to give some advice to girls who are still hesitating
- Jetson Nano 从入门到实战(案例:Opencv配置、人脸检测、二维码检测)
- Leecode learning notes - the shortest path for a robot to reach its destination
猜你喜欢
Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
一线城市软件测试工资——你拖后腿了吗
How transformers Roberta adds tokens
【Proteus仿真】Arduino UNO+数码管显示4x4键盘矩阵按键
Pit entry machine learning: I. Introduction
折叠屏将成国产手机分食苹果市场的重要武器
Sumati gamefi ecological overview, element design in the magical world
华为、阿里等大厂程序员真的好找对象吗?
Software testing salary in first tier cities - are you dragging your feet
随机推荐
Modifying universal render data at runtime
[I.MX6UL] U-Boot移植(六) 网络驱动修改 LAN8720A
mysql命令备份
1-6搭建Win7虚拟机环境
高数 | 精通中值定理 解题套路汇总
ida中交叉引用的解析
Please run IDA with elevated permissons for local debugging.
同花顺是正规平台吗?同花顺开户安全吗
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(4)—— 修改 oracle11g rac 集群的 scanIP
Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
Investigation on key threats of cloud computing applications in 2022
vie的刷新机制
Detailed explanation of cache (for the postgraduate entrance examination of XD)
Is it out of reach to enter Ali as a tester? Here may be the answer you want
F - Spices(线性基)
[STL source code analysis] configurator (to be supplemented)
如何卸载cuda
运行时修改Universal Render Data
Charles packet capturing tool
It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets