#rw-lock #mutex #no-std

no-std syncrs

spinlock-based syncronization primitives for no_std enviroments

7 releases (4 breaking)

Uses new Rust 2024

0.5.0 Jun 21, 2025
0.4.0 Jun 21, 2025
0.3.0 Jun 15, 2025
0.2.1 Jun 15, 2025
0.1.2 Jun 8, 2025

#1418 in Concurrency

Download history

355 downloads per month

GPL-3.0-only

44KB
637 lines

Spinlock-based synchronization primitives

The following synchronization primitives are implemented

  • [Mutex]
  • [RwLock]
  • [OnceLock]
  • [LazyLock]
  • [Condvar]
  • [Arc]")]

Examples

Mutex

use syncrs::{Mutex, LazyLock};

static N: Mutex<u32> = Mutex::new(0);

let threads = (0..10).map(|_|{
    std::thread::spawn(move || {
        let mut sync_n = N.lock();
        for _ in 0..10 {
            *sync_n += 1;
        }
    })
}).collect::<Vec<_>>();

for t in threads {
    t.join().unwrap();
}

assert_eq!(*N.lock(), 100);

LazyLock

use syncrs::LazyLock;
use std::collections::HashMap;

static MAP: LazyLock<HashMap<i32, String>> = LazyLock::new(|| {
    let mut map = HashMap::new();
    for n in 0..10 {
        map.insert(n, format!("{n}"));
    }
    map
});

let map = MAP.get(); /* MAP is initialized at this point */
assert_eq!(
    map.get(&4).map(|s| s.as_str()),
    Some("4"),
);

Sync(rs)

Spinlock-based syncronization primitives for no_std enviroments

Includes

  • Mutex
  • RwLock
  • OnceLock
  • LazyLock
  • Condvar
  • Arc

== Features

alloc (default: off) Implement alloc-dependent primitives (Arc). This feature depends on the allocator-api2 crate, to provide support for the allocator api on stable rust.

== Documentation == To build the documentation, run cargo doc, or browse it online at https://docs.rs/syncrs

==== Copyright (C) 2025 Saúl Valdelvira

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.

Dependencies

~77KB