Struct sync::raw::RWLock[src]
pub struct RWLock {
// some fields omitted
}A blocking, no-starvation, reader-writer lock with an associated condvar.
Failure
A task which fails while holding an rwlock will unlock the rwlock as it unwinds.
Methods
impl RWLock
fn new() -> RWLock
Create a new rwlock, with one associated condvar.
fn new_with_condvars(num_condvars: uint) -> RWLock
Create a new rwlock, with a specified number of associated condvars. Similar to mutex_with_condvars.
fn read<'a>(&'a self) -> RWLockReadGuard<'a>
Acquires a read-lock, returning an RAII guard that will unlock the lock when dropped. Calls to 'read' from other tasks may run concurrently with this one.
fn write<'a>(&'a self) -> RWLockWriteGuard<'a>
Acquire a write-lock, returning an RAII guard that will unlock the lock when dropped. No calls to 'read' or 'write' from other tasks will run concurrently with this one.
You can also downgrade a write to a read by calling the downgrade
method on the returned guard. Additionally, the guard will contain a
Condvar attached to this lock.
Example
extern crate sync; fn main() { use sync::raw::RWLock; let lock = RWLock::new(); let write = lock.write(); // ... exclusive access ... let read = write.downgrade(); // ... shared access ... drop(read); }use sync::raw::RWLock; let lock = RWLock::new(); let write = lock.write(); // ... exclusive access ... let read = write.downgrade(); // ... shared access ... drop(read);