golang waitgroup
var wg sync.WaitGroup
for i := 1; i <= 5; i++ {
wg.Add(1)
go func(wg *sync.WaitGroup) {
wg.Done()
}()
}
wg.Wait()
golang waitgroup
var wg sync.WaitGroup
for i := 1; i <= 5; i++ {
wg.Add(1)
go func(wg *sync.WaitGroup) {
wg.Done()
}()
}
wg.Wait()
wait group golang
package main
import (
"fmt"
"sync"
"time"
)
func worker(id int, wg *sync.WaitGroup) {
defer wg.Done()
fmt.Printf("Worker %d startingn", id)
time.Sleep(time.Second)
fmt.Printf("Worker %d donen", id)
}
func main() {
var wg sync.WaitGroup
for i := 1; i <= 5; i++ {
wg.Add(1)
go worker(i, &wg)
}
wg.Wait()
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us