[src]

Struct sync::mutex::StaticMutex

pub struct StaticMutex {
    // some fields omitted
}

The static mutex type is provided to allow for static allocation of mutexes.

Note that this is a separate type because using a Mutex correctly means that it needs to have a destructor run. In Rust, statics are not allowed to have destructors. As a result, a StaticMutex has one extra method when compared to a Mutex, a destroy method. This method is unsafe to call, and documentation can be found directly on the method.

Example

use sync::mutex::{StaticMutex, MUTEX_INIT};

static mut LOCK: StaticMutex = MUTEX_INIT;

unsafe {
    let _g = LOCK.lock();
    // do some productive work
}
// lock is unlocked here.

Methods

impl StaticMutex

fn try_lock<'a>(&'a self) -> Option<Guard<'a>>

Attempts to grab this lock, see Mutex::try_lock

fn lock<'a>(&'a self) -> Guard<'a>

Acquires this lock, see Mutex::lock

unsafe fn destroy(&self)

Deallocates resources associated with this static mutex.

This method is unsafe because it provides no guarantees that there are no active users of this mutex, and safety is not guaranteed if there are active users of this mutex.

This method is required to ensure that there are no memory leaks on all platforms. It may be the case that some platforms do not leak memory if this method is not called, but this is not guaranteed to be true on all platforms.