Reader-writer locks v0.1.0
RwLock<T>
pub struct RwLock<T> {
// private fields
}
A value guarded by a lock that many readers or one writer may hold, shared between the threads that hold a handle.
Clone gives another handle to the same value. The value is destroyed when the last handle and the last guard are
gone. A handle is not copied.
Type parameters
| Name | Description |
|---|---|
T | the type of the guarded value |
Constructors
RwLock
pub func RwLock(value: T) -> RwLock<T>
A new lock guarding value. Running out of memory for it is a program error.
| Name | Type | Description |
|---|---|---|
value | T | the value to guard |
Returns: the first handle to it
Methods
Clone
pub func Clone(self: &RwLock<T>) -> RwLock<T>
Another handle to the same value.
Returns: the handle
Read
pub func Read(self: &RwLock<T>) -> ReadGuard<T>
Takes a shared hold, waiting while a writer holds the lock.
Returns: the read guard
Write
pub func Write(self: &RwLock<T>) -> WriteGuard<T>
Takes the exclusive hold, waiting while any reader or writer holds the lock.
Returns: the write guard
Destructor
~RwLock
func ~RwLock(self: &var RwLock<T>)
ReadGuard<T>
pub struct ReadGuard<T> {
// private fields
}
A shared hold on an RwLock<T>: the value may be read, and other readers may hold it too.
Type parameters
| Name | Description |
|---|---|
T | the type of the guarded value |
Methods
Get
pub func Get(self: &ReadGuard<T>) -> *T
The guarded value, to read while the guard holds the lock.
Returns: the value's address
Destructor
~ReadGuard
func ~ReadGuard(self: &var ReadGuard<T>)
WriteGuard<T>
pub struct WriteGuard<T> {
// private fields
}
The exclusive hold on an RwLock<T>: the value may be read and written, and nobody else holds the lock.
Type parameters
| Name | Description |
|---|---|
T | the type of the guarded value |
Methods
Get
pub func Get(self: &WriteGuard<T>) -> *var T
The guarded value, which this thread alone may read and write while the guard holds the lock.
Returns: the value's address
Destructor
~WriteGuard
func ~WriteGuard(self: &var WriteGuard<T>)