Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 1.27 KB

README.md

File metadata and controls

44 lines (31 loc) · 1.27 KB

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.