misc/cgo/gmp/fib.go GO 46 lines View on github.com → Search inside
1// Copyright 2009 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.45//go:build ignore67// Compute Fibonacci numbers with two goroutines8// that pass integers back and forth.  No actual9// concurrency, just threads and synchronization10// and foreign code on multiple pthreads.1112package main1314import (15	big "."16	"runtime"17)1819func fibber(c chan *big.Int, out chan string, n int64) {20	// Keep the fibbers in dedicated operating system21	// threads, so that this program tests coordination22	// between pthreads and not just goroutines.23	runtime.LockOSThread()2425	i := big.NewInt(n)26	if n == 0 {27		c <- i28	}29	for {30		j := <-c31		out <- j.String()32		i.Add(i, j)33		c <- i34	}35}3637func 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}

Code quality findings 1

Infinite loop detected; ensure it has a proper exit condition (e.g., break, return) to avoid unintentional resource consumption or hangs
info correctness infinite-loop
for {

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.