| Crates.io | meowtex |
| lib.rs | meowtex |
| version | 0.1.0 |
| created_at | 2025-07-24 13:21:45.780549+00 |
| updated_at | 2025-07-24 13:21:45.780549+00 |
| description | Saddened by the feeling that Rust multitasking types are not puppy-/kittycoded enough for you? Then this crate is for you! |
| homepage | |
| repository | https://github.com/bitfl0wer/meowtex |
| max_upload_size | |
| id | 1766025 |
| size | 20,980 |
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();