Source file src/runtime/testdata/testgoroutineleakprofile/goker/cockroach584.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a MIT
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"os"
     9  	"runtime"
    10  	"runtime/pprof"
    11  	"sync"
    12  )
    13  
    14  func init() {
    15  	register("Cockroach584", Cockroach584)
    16  }
    17  
    18  type gossip_cockroach584 struct {
    19  	mu     sync.Mutex // L1
    20  	closed bool
    21  }
    22  
    23  func (g *gossip_cockroach584) bootstrap() {
    24  	for {
    25  		g.mu.Lock()
    26  		if g.closed {
    27  			// Missing g.mu.Unlock
    28  			break
    29  		}
    30  		g.mu.Unlock()
    31  	}
    32  }
    33  
    34  func (g *gossip_cockroach584) manage() {
    35  	for {
    36  		g.mu.Lock()
    37  		if g.closed {
    38  			// Missing g.mu.Unlock
    39  			break
    40  		}
    41  		g.mu.Unlock()
    42  	}
    43  }
    44  
    45  func Cockroach584() {
    46  	prof := pprof.Lookup("goroutineleak")
    47  	defer func() {
    48  		for i := 0; i < yieldCount; i++ {
    49  			// Yield several times to allow the child goroutine to run.
    50  			runtime.Gosched()
    51  		}
    52  		prof.WriteTo(os.Stdout, 2)
    53  	}()
    54  
    55  	g := &gossip_cockroach584{
    56  		closed: true,
    57  	}
    58  	go func() { // G1
    59  		g.bootstrap()
    60  		g.manage()
    61  	}()
    62  }
    63  

View as plain text