Re: [go-nuts] uninitialized channel

74 views
Skip to first unread message
Message has been deleted

Russ Cox

unread,
Oct 31, 2011, 4:24:37 PM10/31/11
to Awaken, golang-nuts
I get this output, which seems very clear as to
what the code might choose to do differently:

throw: all goroutines are asleep - deadlock!

goroutine 1 [select (no cases)]:
main.main()
/Users/rsc/x.go:20 +0x34

goroutine 2 [chan send (nil chan)]:
main.produce()
/Users/rsc/x.go:6 +0x39
created by main.main
/Users/rsc/x.go:18 +0x1f

goroutine 3 [chan receive (nil chan)]:
main.consume()
/Users/rsc/x.go:12 +0x31
created by main.main
/Users/rsc/x.go:19 +0x2d

Awaken

unread,
Oct 31, 2011, 4:40:40 PM10/31/11
to golang-nuts
Sorry I pasted in the wrong code.
Here is the code that produce the buggy behavior:
package main

import (
"fmt"
)

var queue chan string

//func produce() {
// for {
// queue <-"dafjadsl"
// }
//}

func consume() {
for {
//fmt.Println("dflasdjf")
product := <-queue
fmt.Println(product)
}
}

func init() {
// queue = make(chan string)
}

func main() {
// go produce()
go consume()
var command string
for {
fmt.Scanln(&command)
go func() {
queue <- command
}()

Russ Cox

unread,
Oct 31, 2011, 4:44:25 PM10/31/11
to Awaken, golang-nuts
When you get tired of waiting for your program,
you can killall -ABRT 6.out, which will print:


SIGABRT: abort
pc: 0x3d374

syscall.Syscall()
/Users/rsc/g/go/src/pkg/syscall/asm_darwin_amd64.s:24 +0x2a
syscall.Read(0x0, 0xf84001c098, 0x400000001, 0xf84001c000, 0x2bc90, ...)
/Users/rsc/g/go/src/pkg/syscall/zsyscall_darwin_amd64.go:680 +0x62
os.(*File).read(0xf840019000, 0xf84001c098, 0x400000001, 0x4, 0x1d283, ...)
/Users/rsc/g/go/src/pkg/os/file_unix.go:169 +0x43
os.(*File).Read(0xf840019000, 0xf84001c098, 0x400000001, 0x1, 0x0, ...)
/Users/rsc/g/go/src/pkg/os/file.go:68 +0x83
fmt.(*readRune).readByte(0xf84001c080, 0x20d1010, 0x0, 0x0, 0x8, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:299 +0x141
fmt.(*readRune).ReadRune(0xf84001c080, 0x0, 0x0, 0x0, 0x1dcf0, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:312 +0x41
fmt.(*ss).ReadRune(0xf840021000, 0x0, 0x0, 0x0, 0x8, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:191 +0xe0
fmt.(*ss).getRune(0xf840021000, 0x6db64, 0x4, 0x1f32c)
/Users/rsc/g/go/src/pkg/fmt/scan.go:211 +0x27
fmt.(*ss).skipSpace(0xf840021000, 0x0, 0x6db64, 0x7871767300000004)
/Users/rsc/g/go/src/pkg/fmt/scan.go:390 +0x25
fmt.(*ss).convertString(0xf840021000, 0x76, 0x0, 0xf800000000, 0x1, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:768 +0x98
fmt.(*ss).scanOne(0xf840021000, 0x76, 0x3e950, 0xf840002160, 0x100000000, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:934 +0xf91
fmt.(*ss).doScan(0xf840021000, 0x2111f78, 0x100000001, 0xf800000000, 0x0, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:995 +0xbe
fmt.Fscanln(0xf8400191e0, 0xf840019000, 0x2111f78, 0x100000001,
0xf840019000, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:125 +0x93
fmt.Scanln(0x2111f78, 0x100000001, 0x3e950, 0x0, 0x0, ...)
/Users/rsc/g/go/src/pkg/fmt/scan.go:79 +0x7b
main.main()
/Users/rsc/x.go:32 +0xa9

goroutine 2 [chan receive (nil chan)]:
main.consume()
/Users/rsc/x.go:18 +0x31
created by main.main
/Users/rsc/x.go:29 +0x23

goroutine 3 [chan send (nil chan)]:
main._func_001(0xf840002160, 0x0)
/Users/rsc/x.go:34 +0x3f
created by main.main
/Users/rsc/x.go:35 +0xbe

goroutine 4 [chan send (nil chan)]:
main._func_001(0xf840002160, 0x0)
/Users/rsc/x.go:34 +0x3f
created by main.main
/Users/rsc/x.go:35 +0xbe

Reply all
Reply to author
Forward
0 new messages