package main
import (
"context"
"syscall"
"time"
"unsafe"
)
/*
int goexit(void* func)
{
((int (*)())func)();
return 0;
}
*/
import "C"
func main() {
go func() {
time.Sleep(10e9)
can()
}()
ptr := syscall.NewCallback(wait)
C.goexit(unsafe.Pointer(ptr))
}
var ctx, can = context.WithCancel(context.Background())
func wait() int {
<-ctx.Done()
return 0
}
Go1.10用Go函数控制C函数的生命周期
最新推荐文章于 2024-04-08 16:07:10 发布