Expand description
Thread affinity and cooperative main-thread pump for TaskManager.
Most DCC and game-engine host APIs are UI / main-thread pinned — calling
them from a worker thread either throws or causes a segfault. This module
adds a first-class ThreadAffinity concept to the [TaskManager] ecosystem
and a cooperative MainThreadPump so the host can drain the main-thread
work queue from its own idle callback.
§Design
- Yield points are cooperative: a task must periodically check
[
TaskHandle::is_cancelled] or simply complete quickly. There is no pre-emption, mirroring the Go scheduler and Unity’sEditorApplication. MainThreadPump::pumpdrains work items up to a wall-clockbudget— it never blocks longer than that, keeping the host’s frame rate intact.
§DCC host integration examples
| Host | Idle callback |
|---|---|
| Maya | cmds.scriptJob(idleEvent=pump_fn) |
| Houdini | hdefereval.execute_deferred_after_waiting |
| 3dsMax | pymxs.run_at_ui_idle |
| Blender | bpy.app.timers.register |
| Unity Editor | EditorApplication.update |
| Unreal | FTSTicker / AsyncTask(ENamedThreads::GameThread, …) |
§Example
use ipckit::{MainThreadPump, ThreadAffinity, TaskManager, TaskBuilder};
use std::time::Duration;
let manager = TaskManager::new(Default::default());
let pump = MainThreadPump::new();
// Register a "main-thread" task
let handle = manager.create(
TaskBuilder::new("update-ui", "ui")
.affinity(ThreadAffinity::Main)
);
// Dispatch work to the main thread
pump.dispatch(move || {
handle.start();
handle.complete(serde_json::json!({"updated": true}));
});
// In the host idle callback:
let stats = pump.pump(Duration::from_millis(8));
assert_eq!(stats.processed, 1);Structs§
- Main
Thread Pump - Cooperative pump that drains main-thread work items on demand.
- Pump
Stats - Statistics returned by a single
MainThreadPump::pumpcall.
Enums§
- Thread
Affinity - Controls which thread a task must execute on.