Open lemon-mint opened 3 weeks ago
CC @golang/runtime
I'm confused: what use case does this proposal address? Is handling thread-local storage on a locked Go routine in order to interface with non-Go code using thread-local storage? Or does it try to tackle Go routine local storage, then it appears to be wrongly using PIDs (it's probably using PIDs wrongly anyway)?
Proposal Details
This proposal introduces a new package,
runtime/local
, providing an API for per-P local storage in Go. This enables efficient and race-free access to shared yet locally scoped data, like random number generator states or per-P Logger, without the overhead of locks or cas loop.Several packages within the standard library, including
runtime.fastrand
andsync.Pool
, already utilize per-P or per-M storage internally for performance optimization. This proposal aims to expose a similar mechanism through a public API, enables developers to leverage this approach for their own concurrency needs.This proposal introduces the runtime/local package with the following API:
The proposed package name candidates are following:
runtime/local
runtime/threadlocal
runtime/plocal
runtime/tls
Open Issues: