Skip to main content

Crate windows_threading

Crate windows_threading 

Source
Expand description

§windows-threading

The windows-threading crate wraps the Windows thread pool.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-threading]
version = "0.100"

Submit work to the default pool:

windows_threading::submit(|| {
    println!("thread: {}", windows_threading::thread_id());

    loop {
        println!(".");
        windows_threading::sleep(1000);
    }
});

Process an iterator in parallel:

let counter = std::sync::RwLock::<usize>::new(0);

windows_threading::for_each(0..10, |value| {
    println!("thread: {}, value: {value}", windows_threading::thread_id());
    let mut counter = counter.write().unwrap();
    *counter += value;
});

assert_eq!(*counter.read().unwrap(), 45);

Structs§

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

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.
thread_id
The thread identifier of the calling thread.