I'm trying a basic multithreaded program in go. I fire a parallel goroutine
and wait for it to finish.
package main
import (
"fmt"
"sync"
"time"
)
func main() {
messages := make(chan int)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Second * 3)
messages <- 1
fmt.Println("Stage 1 Posted")
}()
fmt.Println("Stage 1 Ends")
wg.Wait()
close(messages)
}
However, I see an error which i believe is not correct.
$ ./go-examples
Stage 1 Ends
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [semacquire]:
sync.runtime_Semacquire(0x8201ca2bc)
/usr/local/go/src/runtime/sema.go:47 +0x26
sync.(*WaitGroup).Wait(0x8201ca2b0)
/usr/local/go/src/sync/waitgroup.go:127 +0xb4
main.main()
/Users/satyam/ws/src/github.com/satyamsi/go-examples/main.go:25 +0x163
goroutine 5 [chan send]:
main.main.func1(0x8201ca2b0, 0x8201d80c0)
/Users/satyam/ws/src/github.com/satyamsi/go-examples/main.go:19 +0x86
created by main.main
/Users/satyam/ws/src/github.com/satyamsi/go-examples/main.go:21 +0x9a
Is there a requirement that the programmer has to make sure that there is
always an idle thread ? Or is this a bug ?
Satyam
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.