Created
February 25, 2014 14:59
-
-
Save bgnori/9210455 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"code.google.com/p/go-tour/tree" | |
) | |
// Walk walks the tree t sending all values | |
// from the tree to the channel ch. | |
func Walk(t *tree.Tree, ch chan int) { | |
Walk(t.Left, ch) | |
ch <- t.Value | |
Walk(t.Right, ch) | |
} | |
// Same determines whether the trees | |
// t1 and t2 contain the same values. | |
func Same(t1, t2 *tree.Tree) bool { | |
ch1 := make(chan int, 100) | |
ch2 := make(chan int, 100) | |
go Walk(t1, ch1) | |
go Walk(t2, ch2) | |
for <- ch1 == <- ch2 { | |
} | |
return false | |
} | |
func main() { | |
if Same(tree.New(1), tree.New(1)) { | |
fmt.Println("yay") | |
}else { | |
fmt.Println("oh...") | |
} | |
} |
This file contains 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
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal 0xb code=0xffffffff addr=0x0 pc=0x2002e] | |
goroutine 3 [running]: | |
runtime.panic(0xefc20, 0x1b6244) | |
/tmp/sandbox/go/src/pkg/runtime/panic.c:266 +0xe0 | |
runtime.panicstring(0x1b6244, 0x0) | |
/tmp/sandbox/go/src/pkg/runtime/panic.c:489 +0x120 | |
runtime.sigpanic() | |
/tmp/sandbox/go/src/pkg/runtime/os_nacl.c:254 +0x80 | |
main.Walk(0x0, 0x1054b540) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:11 +0x2e | |
main.Walk(0x1052f160, 0x1054b540) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:11 +0x60 | |
main.Walk(0x1052f130, 0x1054b540) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:11 +0x60 | |
main.Walk(0x1052f120, 0x1054b540) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:11 +0x60 | |
main.Walk(0x1052f110, 0x1054b540) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:11 +0x60 | |
runtime.goexit() | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:1394 | |
created by main.Same | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:21 +0xa0 | |
goroutine 1 [chan receive]: | |
runtime.park(0x23460, 0x1054b56c, 0x1b6694, 0x10501790) | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:1342 +0x80 | |
runtime.chanrecv(0xd9ec0, 0x1054b540, 0xfeee1f08, 0x0, 0x0, ...) | |
/tmp/sandbox/go/src/pkg/runtime/chan.goc:305 +0x2c0 | |
runtime.chanrecv1(0xd9ec0, 0x1054b540, 0x64, 0x0) | |
/tmp/sandbox/go/src/pkg/runtime/chan.goc:360 +0x40 | |
main.Same(0x1052f110, 0x1052f1b0, 0x1052f1b0, 0x6980) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:24 +0x100 | |
main.main() | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:31 +0x80 | |
runtime.main() | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:220 +0x1c0 | |
runtime.goexit() | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:1394 | |
goroutine 2 [syscall]: | |
runtime.notetsleepg(0xfeefdf88, 0x0, 0xf8475800, 0xd) | |
/tmp/sandbox/go/src/pkg/runtime/lock_sema.c:254 +0xa0 | |
runtime.MHeap_Scavenger() | |
/tmp/sandbox/go/src/pkg/runtime/mheap.c:463 +0xc0 | |
runtime.goexit() | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:1394 | |
created by runtime.main | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:179 | |
goroutine 4 [runnable]: | |
main.Walk(0x1052f1b0, 0x1054b700) | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:10 | |
runtime.goexit() | |
/tmp/sandbox/go/src/pkg/runtime/proc.c:1394 | |
created by main.Same | |
/tmpfs/gosandbox-27483c41_bba89adc_7ac47c0a_3326acef_21b77f1d/prog.go:22 +0xe0 | |
[process exited with non-zero status] | |
Program exited. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
goの参照はnilの可能性がある. if t.Left != nilとかする