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