Expand description
Graceful shutdown and signal handling for persistent GPU kernels.
Persistent GPU kernels run indefinitely and must be shut down cleanly to
avoid GPU resource leaks, corrupted state, or orphaned device memory.
This module provides infrastructure for capturing OS signals (SIGTERM,
SIGINT / Ctrl-C) and propagating a shutdown request to all interested
parties via a lightweight, clone-able ShutdownSignal.
§Overview
GracefulShutdown– registers signal handlers and owns the shutdown lifecycle (signal capture, grace period, force termination).ShutdownSignal– a cheap, clone-able handle that kernels and background tasks can poll or.awaitto learn about a pending shutdown.ShutdownGuard– returned byGracefulShutdown::install; dropping the guard cancels the signal listener.
§Example
ⓘ
use ringkernel_core::shutdown::GracefulShutdown;
use std::time::Duration;
#[tokio::main]
async fn main() {
let shutdown = GracefulShutdown::new(Duration::from_secs(5));
let signal = shutdown.signal();
// Hand `signal` clones to kernel loops, background tasks, etc.
let guard = shutdown.install();
// In a kernel loop:
loop {
if signal.is_shutdown_requested() {
break;
}
// ... do work ...
}
// Or await the signal:
// signal.wait().await;
guard.wait().await;
}Structs§
- Graceful
Shutdown - Builder and coordinator for graceful shutdown of persistent GPU kernels.
- Shutdown
Guard - Guard returned by
GracefulShutdown::install. - Shutdown
Signal - A lightweight, clone-able handle for checking or awaiting shutdown.