Source file
misc/cgo/gmp/fib.go
1
2
3
4
5
6
7
8
9
10
11
12
13 package main
14
15 import (
16 big "."
17 "runtime"
18 )
19
20 func fibber(c chan *big.Int, out chan string, n int64) {
21
22
23
24 runtime.LockOSThread()
25
26 i := big.NewInt(n)
27 if n == 0 {
28 c <- i
29 }
30 for {
31 j := <-c
32 out <- j.String()
33 i.Add(i, j)
34 c <- i
35 }
36 }
37
38 func main() {
39 c := make(chan *big.Int)
40 out := make(chan string)
41 go fibber(c, out, 0)
42 go fibber(c, out, 1)
43 for i := 0; i < 200; i++ {
44 println(<-out)
45 }
46 }
47
View as plain text