tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
46
Task/Program-termination/Go/program-termination-2.go
Normal file
46
Task/Program-termination/Go/program-termination-2.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
const problem = true
|
||||
|
||||
func main() {
|
||||
fmt.Println("main program start")
|
||||
|
||||
// this will get run on exit
|
||||
defer paperwork()
|
||||
|
||||
// this will not run to completion
|
||||
go pcj()
|
||||
|
||||
// this will not get run on exit
|
||||
rec := &requiresExternalCleanup{"external object"}
|
||||
runtime.SetFinalizer(rec, cleanup)
|
||||
|
||||
if problem {
|
||||
fmt.Println("main program returning")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func paperwork() {
|
||||
fmt.Println("i's dotted, t's crossed")
|
||||
}
|
||||
|
||||
func pcj() {
|
||||
fmt.Println("there's uncle Joe")
|
||||
time.Sleep(1e10)
|
||||
fmt.Println("movin kinda slow")
|
||||
}
|
||||
|
||||
type requiresExternalCleanup struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func cleanup(rec *requiresExternalCleanup) {
|
||||
fmt.Println(rec.id, "cleanup")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue