github.com/mattn/go@v0.0.0-20171011075504-07f7db3ea99f/test/fixedbugs/issue10958.go (about)

     1  // +build !nacl,disabled_see_issue_18589
     2  // buildrun -t 10  -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
     3  
     4  // Copyright 2016 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  // Test is disabled because it flakes when run in all.bash
     9  // on some platforms, but is useful standalone to verify
    10  // that rescheduling checks are working (and we may wish
    11  // to investigate the flake, since it suggests that the
    12  // loop rescheduling check may not work right on those
    13  // platforms).
    14  
    15  // This checks to see that call-free infinite loops do not
    16  // block garbage collection.  IF YOU RUN IT STANDALONE without
    17  // -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
    18  // build, it should hang.
    19  
    20  package main
    21  
    22  import (
    23  	"runtime"
    24  )
    25  
    26  var someglobal1 int
    27  var someglobal2 int
    28  var someglobal3 int
    29  
    30  //go:noinline
    31  func f() {}
    32  
    33  func standinacorner1() {
    34  	for someglobal1&1 == 0 {
    35  		someglobal1++
    36  		someglobal1++
    37  	}
    38  }
    39  
    40  func standinacorner2(i int) {
    41  	// contains an irreducible loop containing changes to memory
    42  	if i != 0 {
    43  		goto midloop
    44  	}
    45  
    46  loop:
    47  	if someglobal2&1 != 0 {
    48  		goto done
    49  	}
    50  	someglobal2++
    51  midloop:
    52  	someglobal2++
    53  	goto loop
    54  
    55  done:
    56  	return
    57  }
    58  
    59  func standinacorner3() {
    60  	for someglobal3&1 == 0 {
    61  		if someglobal3&2 != 0 {
    62  			for someglobal3&3 == 2 {
    63  				someglobal3++
    64  				someglobal3++
    65  				someglobal3++
    66  				someglobal3++
    67  			}
    68  		}
    69  		someglobal3++
    70  		someglobal3++
    71  		someglobal3++
    72  		someglobal3++
    73  	}
    74  }
    75  
    76  func main() {
    77  	go standinacorner1()
    78  	go standinacorner2(0)
    79  	go standinacorner3()
    80  	// println("About to stand in a corner1")
    81  	for someglobal1 == 0 {
    82  		runtime.Gosched()
    83  	}
    84  	// println("About to stand in a corner2")
    85  	for someglobal2 == 0 {
    86  		runtime.Gosched()
    87  	}
    88  	// println("About to stand in a corner3")
    89  	for someglobal3 == 0 {
    90  		runtime.Gosched()
    91  	}
    92  	// println("About to GC")
    93  	runtime.GC()
    94  	// println("Success")
    95  }