Documentation
¶
Index ¶
Constants ¶
View Source
const ( // GOOS is the running program's operating system target: // one of darwin, freebsd, linux, and so on. // To view possible combinations of GOOS and GOARCH, run "go tool dist list". GOOS string = os.GOOS // GOARCH is the running program's architecture target: // one of 386, amd64, arm, s390x, and so on. GOARCH string = arch.GOARCH )
Variables ¶
This section is empty.
Functions ¶
func KeepAlive ¶
func KeepAlive(x any)
KeepAlive marks its argument as currently reachable. This ensures that the object is not freed, and its finalizer is not run, before the point in the program where KeepAlive is called.
A very simplified example showing where KeepAlive is required:
type File struct { d int }
d, err := syscall.Open("/file/path", syscall.O_RDONLY, 0)
// ... do something if err != nil ...
p := &File{d}
runtime.SetFinalizer(p, func(p *File) { syscall.Close(p.d) })
var buf [10]byte
n, err := syscall.Read(p.d, buf[:])
// Ensure p is not finalized until Read returns.
runtime.KeepAlive(p)
// No more uses of p after this point.
Without the KeepAlive call, the finalizer could run at the start of syscall.Read, closing the file descriptor before syscall.Read makes the actual system call.
Note: KeepAlive should only be used to prevent finalizers from running prematurely. In particular, when used with unsafe.Pointer, the rules for valid uses of unsafe.Pointer still apply.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package asan to satisfy go linker `loadinternal` when building with -asan
|
Package asan to satisfy go linker `loadinternal` when building with -asan |
|
Package cgo to satisfy go linker `loadinternal` when building with CGO_ENABLED=1
|
Package cgo to satisfy go linker `loadinternal` when building with CGO_ENABLED=1 |
|
Package msan to satisfy go linker `loadinternal` when building with -msan
|
Package msan to satisfy go linker `loadinternal` when building with -msan |
|
Package race to satisfy go linker `loadinternal` when building with -race
|
Package race to satisfy go linker `loadinternal` when building with -race |
Click to show internal directories.
Click to hide internal directories.