Skip to content

Instantly share code, notes, and snippets.

@tjpalmer
tjpalmer / arcmutself.rs
Last active July 16, 2024 23:05
Arc Mutex as self
use std::sync::{Arc, LockResult, Mutex, MutexGuard};
use std::thread;
struct SharedDataStruct {
value: i32,
}
trait SharedData {
fn get_value(&self) -> i32;
fn set_value(&mut self, new_value: i32);
@tjpalmer
tjpalmer / fib.rs
Last active July 15, 2024 22:26
Rust 1.63-compatible RwLock static init example
pub fn init() {
static INIT_ONCE: std::sync::Once = std::sync::Once::new();
INIT_ONCE.call_once(|| {
let mut zero__2 = 0;
{
*ZERO__2.write().unwrap() = Some(zero__2);
}
zero__2 = zero__2;
{
*ZERO__2.write().unwrap() = Some(zero__2);