tg-sync

Crates.iotg-sync
lib.rstg-sync
version0.1.0-preview.1
created_at2026-01-22 13:13:19.355271+00
updated_at2026-01-22 13:13:19.355271+00
descriptionSynchronization primitives for rCore tutorial OS, including mutex, semaphore, and condvar.
homepagehttps://github.com/rcore-os/rCore-Tutorial-in-single-workspace
repositoryhttps://github.com/rcore-os/rCore-Tutorial-in-single-workspace
max_upload_size
id2061516
size16,883
Yiren Zhang (DeathWish5)

documentation

https://docs.rs/tg-sync

README

tg-sync

Synchronization primitives for the rCore tutorial operating system.

Overview

This crate provides essential synchronization primitives for kernel development, including mutexes, semaphores, and condition variables suitable for a teaching operating system.

Features

  • Mutex: Basic mutual exclusion lock
  • MutexBlocking: Blocking mutex with thread scheduling integration
  • Semaphore: Counting semaphore for resource management
  • Condvar: Condition variable for thread synchronization
  • UPIntrFreeCell: Uniprocessor interrupt-free cell for safe interior mutability
  • no_std compatible: Designed for bare-metal kernel environments

Usage

use tg_sync::{Mutex, MutexBlocking, Semaphore, Condvar};
use tg_sync::{UPIntrFreeCell, UPIntrRefMut};

// Use mutex for mutual exclusion
let mutex = MutexBlocking::new();
mutex.lock();
// critical section
mutex.unlock();

// Use semaphore for resource counting
let sem = Semaphore::new(3);
sem.down();
// use resource
sem.up();

// Use condition variable
let condvar = Condvar::new();
condvar.wait();
condvar.signal();

Core Types

  • Mutex - Basic spinlock-based mutex
  • MutexBlocking - Mutex with thread blocking support
  • Semaphore - Counting semaphore
  • Condvar - Condition variable
  • UPIntrFreeCell - Interrupt-safe cell for uniprocessor systems

Dependencies

  • tg-task-manage - For thread scheduling integration

License

Licensed under either of MIT license or Apache License, Version 2.0 at your option.

Commit count: 242

cargo fmt