Skip to main content

Crate windows_threading

Crate windows_threading 

Source
Expand description

§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.

Structs§

Pool
A Pool object represents a private thread pool with its own thread limits.
Scope
A scope to submit closures in.

Enums§

Priority
The order in which the thread pool runs queued callbacks.

Functions§

for_each
Calls the closure on each item in parallel and waits for completion.
sleep
Suspends the execution of the current thread until the time-out interval elapses.
submit
Submits a closure to the default thread pool.
submit_after
Submits a closure to the default thread pool to run once delay has elapsed.
submit_with_priority
Submits a closure to the default thread pool with the given priority.
thread_id
The thread identifier of the calling thread.