#locking #semaphore #operations #sequence #process #mutual #proc-ctx

procsem

Semaphore used to lock thread/task-spanning sequence of operations

2 unstable releases

new 0.2.0 Nov 26, 2024
0.1.0 Feb 3, 2023

#431 in Asynchronous

Download history 4/week @ 2024-07-30 1/week @ 2024-09-17 4/week @ 2024-09-24

72 downloads per month

0BSD license

12KB
167 lines

procsem

The ProcSem is a semaphore used to lock a sequence of operations that may span multiple threads/tasks.


lib.rs:

A simple process semaphore.

(Note: The word process should be read as a sequence of operations, rather than an operating system process).

The ProcSem is intended to allow mutual exclusion of a chain of operations that may span over several threads/tasks.

This is much like a Mutex, but it differs in that it holds no generic parameter and the ProcCtx (the equivalent of Mutex's MutexGuard) is Send, because it is explicitly meant to be passed around between threads/tasks. It supports blocking, nonblocking and async lock acquisition.

Progress reporting

When a ProcSem is created, it can optionally be handed an object that implements StateReporter. If a ProcSem has a StateReporter associated with it, then an acquired ProcCtx can use [ProcCtx::action()], [ProcCtx::progress()] to pass progress information to the StateReporter implementor.

Once a ProcCtx is about to terminate, [ProcCtx::end()] can be used to signal a final message that can be retrieved by the ProcSem object.

Dependencies

~1.1–5.5MB
~25K SLoC