TrAyZeN / spinlock

⛓️ no_std synchronization primitives using spinlock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spinlock

CI

no_std synchonization primitives using spinlock.

⚠️ Disclaimer ⚠️: This implementation is for learning purposes if you want to use a spinlock use the crate spin-rs instead.

What is a spinlock ?

In software engineering, a spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available.

From wikipedia.

Roadmap

  • Mutex
  • RwLock
  • Handle panicking

Example

use std::thread;
use std::sync::Arc;

use spinlock::Mutex;

let count = Arc::new(Mutex::new(0));

let count1 = Arc::clone(&count);
let _ = thread::spawn(move || {
    *count1.lock() += 1;
}).join();

assert_eq!(*count.lock(), 1);

Useful links

License

This project is licensed under MIT License.

About

⛓️ no_std synchronization primitives using spinlock

License:MIT License


Languages

Language:Rust 100.0%