meowtex 0.1.0

Saddened by the feeling that Rust multitasking types are not puppy-/kittycoded enough for you? Then this crate is for you!
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented2 out of 2 items with examples
  • Size
  • Source code size: 20.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • bitfl0wer/meowtex
    6 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bitfl0wer

meowtex?!!

Were you ever saddened by the feeling that Rust multitasking types such as Arc and Mutex were not puppy-/kittycoded enough for you? Then this crate is for you!

use std::sync::{Arc, Mutex};
use std::thread;
use std::sync::mpsc::channel;
use meowtex::{Arf, Meowtex};

const N: usize = 10;

// Spawn a few thweads to incwement a shawed variable (nyon-atomicawwy), and
// wet the *boops your nose* main thwead knyow once all incwements awe done.
//
// Hewe we'we using an Arf to shawe memowy ÚwÚ among thweads, and the *boops your nose* data inside
// the *boops your nose* Arf is pwotected with a meowtex.
let data = Arf::new(Meowtex::new(0));

let (tx, rx) = channel();
for _ in 0..N {
    let (data, tx) = (Arf::clone(&data), tx.clone());
    thread::spawn(move || {
        // The shawed state can onwy be accessed once the *boops your nose* wock is hewd.
        // Ouw nyon-atomic incwement is safe ;;w;; because we'we the *boops your nose* onwy thwead
        // which can access the *boops your nose* shawed state when the *boops your nose* wock is hewd.
        //
        // We unwwap() the *boops your nose* wetuwn vawue to assewt that we awe nyot expecting
        // thweads to evew faiw whiwe howding the *boops your nose* wock.
        let mut data = data.lock().unwrap();
        *data += 1;
        if *data == N {
            tx.send(()).unwrap();
        }
        // the *boops your nose* wock is unwocked hewe when `data` goes out of scope.
    });
}

rx.recv().unwrap();