Last updated: 2026-06-12

Inference Runtime

Process Lock

All API Sections

Cross-process GPU reservation lock keyed by backend and selected device.

ZINC uses a filesystem lock to stop multiple inference processes from loading different models onto the same physical GPU at once, which would otherwise produce confusing OOM failures and unstable benchmark results.

5 exports 2 methods src/gpu/process_lock.zig

5 exports shown

enum

Backend

#
pub const Backend = enum

Backend identifier encoded into the shared GPU lockfile name.

src/gpu/process_lock.zig:10

struct

ProcessLock

#
pub const ProcessLock = struct

Cross-process lock handle that reserves one backend/device pair.

src/gpu/process_lock.zig:16

Methods

2

method

ProcessLock.isHeld

#
pub fn isHeld(self: *const ProcessLock) bool

Return whether the lock currently owns an open lockfile handle.

src/gpu/process_lock.zig:20

constant

AcquireError

#
pub const AcquireError = std.fs.File.OpenError || error{

Errors returned while acquiring a backend/device GPU reservation lock.

src/gpu/process_lock.zig:34

function

lockPath

#
pub fn lockPath(buffer: []u8, backend: Backend, device_index: u32) error{LockPathTooLong}![]const u8

Format the lockfile path for a backend/device pair into the caller-supplied buffer.

Parameters

buffer
Destination slice for the formatted path; must be large enough to hold the formatted path.
backend
The GPU backend whose tag name is embedded in the path.
device_index
Zero-based device index embedded in the path.

Returns

A slice into `buffer` holding the formatted path string, e.g. `/tmp/zinc-gpu-vulkan-0.lock`.

Notes

Returns `error.LockPathTooLong` if `buffer` is too small to hold the formatted path.

src/gpu/process_lock.zig:46

function

acquire

#
pub fn acquire(backend: Backend, device_index: u32) AcquireError!ProcessLock

Acquire the cross-process GPU reservation lock for a backend/device pair.

Opens the lockfile in non-blocking exclusive mode so that a second process attempting to claim the same GPU immediately receives `error.GpuAlreadyReserved` rather than blocking indefinitely.

Parameters

backend
The GPU backend to reserve.
device_index
Zero-based index of the device to reserve within that backend.

Returns

A `ProcessLock` holding the open lockfile handle; caller must call `deinit` to release.

Notes

Returns `error.GpuAlreadyReserved` if another process already holds the lock.

src/gpu/process_lock.zig:63