#cpu #thread #process #multi-thread

multithreading

A simple multithreading library in Rust

6 releases

new 0.2.0 May 20, 2024
0.1.4 Mar 26, 2024

#290 in Concurrency

Download history 215/week @ 2024-03-07 56/week @ 2024-03-14 261/week @ 2024-03-21 78/week @ 2024-03-28 25/week @ 2024-04-04 3/week @ 2024-04-11 123/week @ 2024-05-16

123 downloads per month

MIT license

6KB
109 lines

Multithreading Library Written In Rust


A simple multithreading library written in rust.

Usage

use multithreading::ThreadPool;

fn main() {
    let pool = ThreadPool::new(<number_of_threads_to_use>);
    for i in 0..10 {
        pool.execute(move || {
            // Do something
            println!("Task {}", i);
        });
    }
}

if you want to use all available threads, you can use the crate num_cpus to get the number of available threads.

use multithreading::ThreadPool;
use num_cpus;

fn main() {
    let pool = ThreadPool::new(num_cpus::get());
    for i in 0..10 {
        pool.execute(move || {
            // Do something
            println!("Task {}", i);
        });
    }
}

No runtime deps