]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/mallocfin.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / mallocfin.go
index dc6d74bad6849b78ea4be50482932fb3378a11e8..be6d79b2b8e09ed623639972ac9e9f7ff9a411bb 100644 (file)
@@ -1,10 +1,10 @@
-// $G $D/$F.go && $L $F.$A && ./$A.out
+// run
 
 // Copyright 2009 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// trivial finalizer test
+// Test basic operation of finalizers.
 
 package main
 
@@ -47,18 +47,28 @@ func finalB(b *B) {
        nfinal++
 }
 
+func nofinalB(b *B) {
+       panic("nofinalB run")
+}
+
 func main() {
        runtime.GOMAXPROCS(4)
        for i = 0; i < N; i++ {
                b := &B{i}
                a := &A{b, i}
+               c := new(B)
+               runtime.SetFinalizer(c, nofinalB)
                runtime.SetFinalizer(b, finalB)
                runtime.SetFinalizer(a, finalA)
+               runtime.SetFinalizer(c, nil)
        }
        for i := 0; i < N; i++ {
                runtime.GC()
                runtime.Gosched()
                time.Sleep(1e6)
+               if nfinal >= N*8/10 {
+                       break
+               }
        }
        if nfinal < N*8/10 {
                println("not enough finalizing:", nfinal, "/", N)