Semafy provides synchronization primitives based on concepts from C++ standard threading and synchronization libraries. It includes support for mutexes, condition variables, semaphores, and shared mutexes to facilitate robust concurrent applications in environments supporting shared memory and atomic operations.
- Mutex: Provides exclusive locking to protect shared data from concurrent access.
- ConditionVariable: Allows agents (main thread, web workers) to wait for certain conditions to occur.
- RecursiveMutex: Provides exclusive, recursive locking to protect shared data from concurrent access.
- Semaphore: Implements a semaphore to control access to a finite number of resources.
- SharedMutex: Allows multiple readers or exclusive writer access, facilitating reader-writer scenarios.
-
Error Handling: Includes specific error classes like
MutexError
,MutexOwnershipError
,MutexRelockError
, andTimeoutError
to handle different synchronization scenarios.
NPM:
npm install semafy
Yarn:
yarn add semafy
For security reasons, browsers have certain requirements for using shared memory. These requirements must be met to use this library in a browser. Please see SharedArrayBuffer > Security Requirements for details.
Contributions are welcome! Please submit any bugs, issues, or pull requests to the project's GitHub repository.