Documentation
¶
Overview ¶
Package pythread is the cross-platform threading shim ported from cpython/Python/thread.c. It layers over Go's goroutine scheduler; the platform-specific thread_pthread.h / thread_nt.h files in CPython have no Go counterpart.
In v0.1 the surface is intentionally narrow: Init, stacksize stubs, the TimeoutMax constant, and a Start/Join handle. Lock-acquire retry, TSS, and sys.thread_info land in later phases when their dependencies (state, pytime, sysmod) exist.
Index ¶
Constants ¶
const TimeoutMax int64 = math.MaxInt64 / 1000
TimeoutMax is the maximum lock-acquire timeout in microseconds. Matches PY_TIMEOUT_MAX from CPython's POSIX branch: LLONG_MAX / 1000, so that microseconds * 1000 (nanoseconds) fits in int64.
CPython: Python/thread.c:L39 PY_TIMEOUT_MAX
Variables ¶
This section is empty.
Functions ¶
func GetStacksize ¶
func GetStacksize() int
GetStacksize mirrors PyThread_get_stacksize. Returns 0 until the per-interpreter state lands and can carry a configured stack size.
CPython: Python/thread.c:L76 PyThread_get_stacksize
func Init ¶
func Init()
Init mirrors PyThread_init_thread. The Go runtime is already initialized when the program starts, so this is a no-op kept for source-shape parity.
CPython: Python/thread.c:L47 PyThread_init_thread
func SetStacksize ¶
SetStacksize mirrors PyThread_set_stacksize. Goroutines grow their stacks dynamically, so configuring a fixed size is not meaningful. Returns -2 to signal "not supported", matching the C contract.
CPython: Python/thread.c:L87 PyThread_set_stacksize
Types ¶
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle represents a goroutine started through Start. It records the goroutine's ident and a channel that is closed when the work finishes.
CPython: Python/thread_pthread.h:L329 PyThread_start_joinable_thread (adapted from)
func Start ¶
func Start(fn func()) *Handle
Start runs fn on a new goroutine. fn must not be nil. Panics from fn are recovered; the value is surfaced through Join.
CPython: Python/thread_pthread.h:L328 PyThread_start_joinable_thread