Arf>
Find a file
2025-07-24 15:20:49 +02:00
src feat: inyitiaw commit 2025-07-24 15:12:51 +02:00
.gitignore feat: inyitiaw commit 2025-07-24 15:12:51 +02:00
Cargo.lock feat: inyitiaw commit 2025-07-24 15:12:51 +02:00
Cargo.toml feat: add weadme and wicense fiwes 2025-07-24 15:20:49 +02:00
LICENSE-APACHE feat: add weadme and wicense fiwes 2025-07-24 15:20:49 +02:00
LICENSE-MIT feat: add weadme and wicense fiwes 2025-07-24 15:20:49 +02:00
README.md feat: add weadme and wicense fiwes 2025-07-24 15:20:49 +02:00

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();