当前位置:网站首页>Golang daily question
Golang daily question
2022-06-24 21:07:00 【AcTarjan】
2022-02-16 channel
- Give me a nil channel send data , Cause permanent obstruction
- From a nil channel receive data , Cause permanent obstruction
- To a closed channel send data , cause panic
- From a closed channel receive data , If the buffer is empty , Then return a zero value
- Unbuffered channel It's synchronous , And there's a buffer channel asynchronous
2022-02-17 sync.WaitGroup
func main() {
const N = 10
var wg = &sync.WaitGroup{
}
for i := 0; i < N; i++ {
wg.Add(1) // add 1 goroutine to WaitGroup
go func(i int) {
println(i)
defer wg.Done() //a goroutine finished
}(i)
}
wg.Wait() //wait util all goroutines finish
}
- function : Wait for all threads to end
- wg.Wait() Will block , If there are still threads waiting
- wg.Add() Increase the number of threads that need to wait
- wg.Done() The waiting thread ends , namely wg.Add(-1)
边栏推荐
- JUnit unit test
- Time standard and format
- Intermediary model -- collaboration among departments
- Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably
- Static routing job supplement
- Open function
- The difference between RPC and restful
- Prototype mode -- clone monster Army
- How Fiddler works
- Common self realization functions in C language development
猜你喜欢

Wechat applet custom tabbar

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

What does virtualization mean? What technologies are included? What is the difference with private cloud?

Set up your own website (14)

Web automation: summary of special scenario processing methods

Network security review office starts network security review on HowNet

Mapstacks: data normalization and layered color layer loading

How to apply agile development ideas to other work

Visitor model -- generation gap between young and middle-aged people

基于QT+MySQL的相机租赁管理系统
随机推荐
云计算发展的 4 个阶段,终于有人讲明白了
Use the transparent [x] cross button image in the dialog
Common data model (updating)
Analysis of errors in JSON conversion using objectmapper
Basic properties and ergodicity of binary tree
Procedural life: a few things you should know when entering the workplace
使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
Leetcode (146) - LRU cache
DHCP operation
Shrimp skin test surface treated
Leetcode (455) - distribute cookies
The difference between RPC and restful
OSI notes sorting
Visitor model -- generation gap between young and middle-aged people
Open programmable infrastructure (OPI) project, redefining dpu/ipu
Mapstacks: data normalization and layered color layer loading
Does the developer want to change to software testing?
Common self realization functions in C language development
JMeter installation plug-in, adding [email protected] -Perfmon metric collector listener steps
网络安全审查办公室对知网启动网络安全审查