Go · Threads and Polling

Threads and Polling

import "github.com/unum-cloud/ucall" 1.0.0-rc.1 · b7577426

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ucall/go/threads-and-polling.md' | claude -p "How would this fit my code?"

The package starts no goroutines: every callback runs on a goroutine the application gave to a polling call, which stays on one thread for that call.

  • A route handler runs on the goroutine inside TakeCall or TakeCalls for the event loop that received the request.
  • A PooledBatch handler runs on the goroutine inside TakeBatch or TakeBatches for its endpoint, never on an event loop, while a LocalBatch handler runs inside TakeCall or TakeCalls for the loop whose requests it holds.
  • A server’s peer authorizer runs on the polling goroutine completing the handshake, and a client’s on the goroutine inside TakeCompleted or a blocking call.

Each event loop and each batch endpoint has one polling owner at a time. TakeCalls and TakeBatches run until Server.Stop, while TakeCall and TakeBatch return after one round, waiting up to their timeout, so a loop of them interleaves polling with other work; TakeCall answers PollingRetired once the loop drained after a stop. Server.Stop works from any goroutine, handlers included, and wakes every polling goroutine; Server.Close frees the server once they returned. The first stop drains, answering every request already held before its connection closes, and a second one cuts the replies still in flight. A Request and a Response move between goroutines, while a Client is used by one goroutine at a time. Every thread that polls, replies or reads must run on a CPU supporting the CPU class the server or client resolved at start, so CPUClassSerial is the safe choice on machines mixing CPU generations.

API

Types

PollingPolling is what Server.TakeCall found of its event loop.
server.go:372 ↗
type Polling int

Values

PollingServingiotaPollingServing means the loop serves, or drains what it holds after a stop.
PollingRetiredPollingRetired means the loop drained or cut everything after Server.Stop.
EnumCPUClassCPUClass is a bundle of CPU kernels; CPUClassUnknown sets no ceiling.2
types.go:419 ↗
type CPUClass int32

Values

CPUClassUnknownCPUClassUnknown sets no ceiling, picking the newest class the machine runs.
CPUClassSerialCPUClassSerial runs portable kernels with no SIMD on every machine.
CPUClassMonoversionedCPUClassMonoversioned is the one class a monoversioned build compiles.
CPUClassIntelHaswellCPUClassIntelHaswell runs AVX2 kernels.
CPUClassIntelSkylakeCPUClassIntelSkylake adds AVX-512 kernels.
CPUClassIntelIcelakeCPUClassIntelIcelake adds Ice Lake's AVX-512 extensions and SHA.
CPUClassIntelAlderCPUClassIntelAlder runs AVX2 kernels with SHA and no AVX-512.
CPUClassAWSG2CPUClassAWSG2 runs NEON kernels with the AES and SHA extensions.
CPUClassAppleM4CPUClassAppleM4 adds timed waits to the Graviton5 kernels.
CPUClassAWSG5CPUClassAWSG5 runs the Graviton2 kernels with newer atomics.
CPUClassAlibabaC930CPUClassAlibabaC930 runs RVV kernels with Zawrs waits and Zacas compare-and-swap.
CPUClassIBMPower10CPUClassIBMPower10 runs VSX kernels with short pauses and store atomics.
CPUClassFromNameCPUClassFromName reads a class back from its stable name, "unknown" included.
types.go:455 ↗
func CPUClassFromName(name string) (CPUClass, error)
StringString renders the class's stable name, such as "intel-icelake".
types.go:450 ↗
func (class CPUClass) String() string