#cpu #thread #process #multi-thread

multithreading

A simple multithreading library in Rust

7 releases

0.3.0 Sep 25, 2024
0.2.0 May 20, 2024
0.1.4 Mar 26, 2024

#301 in Concurrency

Download history 3/week @ 2024-06-27 38/week @ 2024-07-04 13/week @ 2024-07-25 2/week @ 2024-09-12 117/week @ 2024-09-19 63/week @ 2024-09-26 9/week @ 2024-10-03 2/week @ 2024-10-10

192 downloads per month

MIT license

8KB
175 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