windows-threading 0.101.0

Windows threading
Documentation

windows-threading

Safe access to the Windows thread pool, including scoped tasks that borrow local data. Use it for CPU or blocking work that does not need a dedicated thread.

Get started

[dependencies]
windows-threading = "0.101"
let total = std::sync::Mutex::new(0);

windows_threading::for_each(0..10, |value| {
    *total.lock().unwrap() += value;
});

assert_eq!(*total.lock().unwrap(), 45);

Choose lifetime and concurrency

submit runs a Send + 'static closure on the default pool without waiting. for_each waits for all items to finish, so its closure can borrow local data.

Use Pool for a private pool and Pool::scope for borrowing tasks. Dropping a pool waits for its work to finish. Avoid waiting on tasks queued to the same constrained pool, and handle expected failures inside callbacks rather than panicking.

Use a dedicated thread for work requiring a stable thread identity or apartment. The pool sample shows scoped work and thread limits.