threadder

Crates.iothreadder
lib.rsthreadder
version0.1.0
sourcesrc
created_at2021-04-23 06:27:49.713688
updated_at2021-04-23 06:27:49.713688
descriptionA multi-threading implementation that does not rely on Futures.
homepage
repositoryhttps://github.com/T-O-R-U-S/threadder
max_upload_size
id388466
size8,941
T•Ø•R•Ü•S (T-O-R-U-S)

documentation

README

Threadder

A simple multithreading implementation. Examples:

use std::{
    thread::sleep,
    time::Duration
};
use threadder::ThreadPool;

fn main() {
    // Warning: Threadpools MUST be declared as mutable!
    // If the threadpool is not mutable, it won't be able to switch threads.
    // Create a 4-thread threadpool
    let mut my_threadpool = ThreadPool::new(4);
    for _ in 0..4 {
        // Clojures can (optionally) be boxed.
        my_threadpool.send(
            || {
                println!("Goodnight, world!");
                sleep(Duration::from_secs(3));
                println!("Goodmorning, world!");
            }
        );
    }
    // MUST be ran at the end of the program. Ensures all threads exit PROPERLY. Without this, 
    // all threads will shut down as soon as the 'main' thread shuts down -- which isn't desirable 
    // when your thread finishes 3 seconds AFTER main does.
    my_threadpool.stop();
    // This drops the transmitter which breaks the listener 
    // loop and joins the thread, allowing it to exit properly without landing the program in an endless loop
}
Commit count: 18

cargo fmt