Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Program-termination/Go/program-termination-1.go
Normal file
5
Task/Program-termination/Go/program-termination-1.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func main() {
|
||||
if problem {
|
||||
return
|
||||
}
|
||||
}
|
||||
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")
|
||||
}
|
||||
13
Task/Program-termination/Go/program-termination-3.go
Normal file
13
Task/Program-termination/Go/program-termination-3.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
func main() {
|
||||
fmt.Println("main program start")
|
||||
|
||||
// this will not get run on os.Exit
|
||||
defer func() {
|
||||
fmt.Println("deferred function")
|
||||
}()
|
||||
|
||||
if problem {
|
||||
fmt.Println("main program exiting")
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
17
Task/Program-termination/Go/program-termination-4.go
Normal file
17
Task/Program-termination/Go/program-termination-4.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
func pcj() {
|
||||
fmt.Println("at the junction")
|
||||
defer func() {
|
||||
fmt.Println("deferred from pcj")
|
||||
}()
|
||||
panic(10)
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("main program start")
|
||||
defer func() {
|
||||
fmt.Println("deferred from main")
|
||||
}()
|
||||
go pcj()
|
||||
time.Sleep(1e9)
|
||||
fmt.Println("main program done")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue