You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func main() {
// sử dụng từ khoá go để tạo goroutine
go fmt.Println("Hello from another goroutine")
fmt.Println("Hello from main goroutine")
// chờ 1 giây để có thể chạy được goroutine <--- wrong
//của hàm fmt.Println trước khi hàm main kết thúc
time.Sleep(time.Second)
}
To Reproduce
Expected behavior
Use other primitive for goroutine synchronization like channel or sync.WaitGroup.
Screenshots
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered:
func main() {
done := make(chan struct{})
go func() {
defer close(done)
fmt.Println("Hello from another goroutine")
}()
fmt.Println("Hello from main goroutine")
<-done
}
But I don't know the process of generating the documentation.
Describe the bug
Examples in https://zalopay-oss.github.io/go-advanced/ch1-basic/ch1-05-concurrency-parallelism.html#154-v%C3%AD-d%E1%BB%A5-goroutine uses
time.Sleep
for synchronization. This is wrong, because when a goroutine is scheduled to run depends on the runtime scheduler, there's no guarantee that it was run aftertime.Sleep
was executed.To Reproduce
Expected behavior
Use other primitive for goroutine synchronization like channel or
sync.WaitGroup
.Screenshots
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: