hppa: Fix g++.dg/modules/bad-mapper-1.C on hpux
[official-gcc.git] / libgo / misc / cgo / gmp / fib.go
blobf453fcf1843b7c13123398a212c0d8cc64935817
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build ignore
6 // +build ignore
8 // Compute Fibonacci numbers with two goroutines
9 // that pass integers back and forth. No actual
10 // concurrency, just threads and synchronization
11 // and foreign code on multiple pthreads.
13 package main
15 import (
16 big "."
17 "runtime"
20 func fibber(c chan *big.Int, out chan string, n int64) {
21 // Keep the fibbers in dedicated operating system
22 // threads, so that this program tests coordination
23 // between pthreads and not just goroutines.
24 runtime.LockOSThread()
26 i := big.NewInt(n)
27 if n == 0 {
28 c <- i
30 for {
31 j := <-c
32 out <- j.String()
33 i.Add(i, j)
34 c <- i
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)