Answer the question
In order to leave comments, you need to log in
How to check spawned goroutines?
Hello, here is a test fiddle
package main
func gorutine(){
for{
time.Sleep(10000*time.Second)
}
}
func main() {
sum := 1
for sum < 1000 {
sum += sum
go gorutine()
}
//ждем пока они выспятся все
}
Answer the question
In order to leave comments, you need to log in
Hello.
1. Goruntine != thread/process. Go decides whether it needs a thread/process.
2. Your example is executed instantly. goroutines do not block the execution flow of the main program.
To "wait for all gorutines to execute", you can use channels or a WaitGroup from the sync package.
3. Your loop will only run 10 times. "sum += sum" and not "sum++" and not "sum = sum + 1"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question