machportkevent

command
v0.6.20 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Command machportkevent demonstrates waiting on Mach ports with kqueue's EVFILT_MACHPORT filter.

It builds a small request/response service: a worker goroutine owns a port set, registers it with a kqueue, and blocks in kevent64 until a message arrives on any member port. Clients send Mach messages to individual ports in that set. One wait covers every port, so adding a port costs nothing at the wait site.

Run it:

go run ./examples/kernel/machportkevent
go run ./examples/kernel/machportkevent -ports=8 -messages=4

Why a dedicated thread

This wait cannot be handed to the Go runtime's network poller. The poller only ever registers EVFILT_READ, EVFILT_WRITE and EVFILT_USER, and a kqueue descriptor has no read(2) interface for it to use, so a blocking kevent64 would stall the P it runs on. runtime.LockOSThread gives the wait a thread of its own, which is what the netpoller would otherwise have avoided.

The trade is real: a blocked thread costs a thread, but it costs no CPU while idle, unlike polling. Whether that is the right trade depends on how often messages arrive relative to how long the process can afford to spin.

Jump to

Keyboard shortcuts

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