procpolicy

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package procpolicy is PiG's GOMAXPROCS policy. pig additive (D174): a process whose environment does not set GOMAXPROCS runs with at most Cap Ps (RPCCap in rpc mode), so the streaming hand-offs of a turn do not wake and park idle Ps, and each parallel section of a session load runs at the runtime default width while it lasts.

Index

Constants

View Source
const Cap = 2

Cap is the most Ps the process runs on outside a parallel section.

View Source
const RPCCap = 1

RPCCap is the most Ps an rpc-mode process runs on outside a parallel section. An rpc turn is a chain of hand-offs between the stdin reader, the agent loop, the provider stream and the stdout writer; on one P each hand-off finds its receiver without waking another P.

Variables

This section is empty.

Functions

func Apply

func Apply()

Apply caps GOMAXPROCS at min(Cap, the runtime default) when the environment does not set GOMAXPROCS. A user's GOMAXPROCS (and GOGC, which the policy never reads) is left alone, and so is a runtime default of Cap or less, which keeps the runtime's automatic updates. It runs before anything else reads or sets GOMAXPROCS, so the width it reads is the runtime default (container-aware since Go 1.25).

func ApplyRPC

func ApplyRPC()

ApplyRPC lowers the cap to RPCCap for an rpc-mode run, under the same rules as Apply. A section open when it runs keeps the default width and closes to the lower cap.

func Widen

func Widen() (narrow func())

Widen opens a parallel section: when Apply capped GOMAXPROCS, the first open section restores the runtime default (runtime.SetDefaultGOMAXPROCS, which recomputes it from the CPU count, affinity and cgroup limit and resumes the runtime's automatic updates), so a worker count read from runtime.GOMAXPROCS(0) inside the section is the default width. It returns the function that closes the section; the caller defers it, so a panicking section closes too. When the last open section closes, GOMAXPROCS goes back to min(the cap, the default at that moment). Sections may nest and run concurrently. Without the cap both are no-ops.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL