Expand description
§declarative_lock
This module provides a thread-aware lock manager for declarative resource locking. It enables threads to explicitly declare which resources they intend to lock, helping to prevent deadlocks and ensuring safe, coordinated access to shared resources in concurrent environments.
Resources must be declared before they can be locked via DeclarativeLock.
Declarations are tracked per thread and managed via
DeclarationGuard, which automatically unregisters resources when dropped. The module also provides
wrappers for resource locking and guards to ensure proper cleanup and usage tracking.
In addition to resource declaration and management, this module provides the DeclarativeLocker type,
which enables safe and controlled locking of declared resources. When a resource is locked, a LockGuard
is returned, granting access to the resource while ensuring proper cleanup and usage tracking when the guard is dropped.
These wrappers help enforce correct locking discipline and prevent common concurrency issues.
§Features
- Fine-grained control over resource usage
- Deadlock prevention through explicit declarations
- Automatic cleanup of resource declarations
- Safe access to shared resources
Structs§
- Declaration
Guard - A guard that represents a successful declaration of resources in the
DeclarativeLock. - Declarative
Lock - A thread-aware lock manager for declarative resource locking.
- Declarative
Locker - A wrapper for managing declarative locking of a resource.
- Lock
Guard - A guard that provides access to a locked resource and ensures proper cleanup.
Enums§
- Declare
Error - Errors that can occur when declaring resources with
DeclarativeLock. - Lock
Error - Errors that can occur when locking a resource with
DeclarativeLocker.