public Mutex(T initialValue)Initializes a new Mutex<T> owning initialValue.
Parameters
initialValue- The initial protected value.
All Types / Ferrous.Concurrency
public sealed class Mutex<T>
A data-owning mutual exclusion primitive inspired by Rust's std::sync::Mutex<T>. The protected value can only be accessed while holding a stack-allocated MutexGuard<T>.
Tpublic Mutex(T initialValue)Initializes a new Mutex<T> owning initialValue.
initialValuepublic MutexGuard<T> Lock() [MustUse]Acquires the mutex and returns a stack-allocated MutexGuard<T> providing exclusive access to the protected value.
public bool TryLock(out MutexGuard<T> guard) [MustUse]Attempts to acquire the mutex without blocking.
guardtrue, contains the acquired MutexGuard<T>; otherwise, the default (unacquired) guard.public void WithLock(Action<T> action)Acquires the lock, invokes action with the protected value, and releases the lock.
actionpublic TResult WithLock<TResult>(Func<T, TResult> func)Acquires the lock, invokes func with the protected value, releases the lock, and returns the result.
TResultfunc.func