Spinlock.rs
A spinlocks implementation in rust
Install / Use
/learn @jorisgio/Spinlock.rsREADME
spinlock-rs
A spinlock implementation in rust
Build
Run cargo build
Usage
The library implements a Reader/Writer lock. When locking a spin lock for shared Read access, you will get a reference to the protected data, and while locking for an exclusive Write access, you will get a mutable reference.
extern crate spinlock;
use spinlock::SpinLock;
fn main() {
let spin = SpinLock::new(0);
// Write access
{
let mut data = spin.write().unwrap();
*data += 1;
}
// Read access
{
let data = spin.read().unwrap();
println!("{}", *data);
}
}
Please note that the spinlock doesn't deal itself with reference counting. You
might want to use Arc<SpinLock<T>> to share the lock between threads.
Credits
The implementation is derived from the spinlock implementation written by Matt Dillon for DragonFlyBSD
Related Skills
node-connect
342.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
85.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
342.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
