Created
April 11, 2025 14:03
-
-
Save jumanji27/0ba697e133e30f0380483ced7b18ec9f to your computer and use it in GitHub Desktop.
go-problem-4.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func worker(id int, wg *sync.WaitGroup) { | |
defer wg.Done() | |
fmt.Printf("Worker %d is working\n", id) | |
time.Sleep(5 * time.Second) | |
} | |
func main() { | |
var wg sync.WaitGroup | |
for i := 1; i <= 10; i++ { | |
wg.Add(1) | |
go worker(i, &wg) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment