Skip to main content

Module shutdown

Module shutdown 

Source
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 .await to learn about a pending shutdown.
  • ShutdownGuard – returned by GracefulShutdown::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§

GracefulShutdown
Builder and coordinator for graceful shutdown of persistent GPU kernels.
ShutdownGuard
Guard returned by GracefulShutdown::install.
ShutdownSignal
A lightweight, clone-able handle for checking or awaiting shutdown.