Mutex
Recursive locking for shared data.
All participants must protect the same data with the same Mutex. After Lock() or successful TryLock(), call Unlock() in finally. Recursive acquisition by the same thread is allowed and requires one release for each level.
Do not hold the mutex during WaitToFinish() or while awaiting an event that the blocked worker must produce. Mutex provides no timeout, cancellation or fairness promise. Thread-safe APIs. Ordinary/recursive acquisition and contention were tested on Windows; stress and invalid unlock were not executed.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
MutexConstructor
public Mutex();Creates a recursive engine mutex. Protects only sections whose participants use the same instance and protocol. Does not make an entire Resource or EntityTree thread-safe. Do not Dispose a held mutex or one still used by workers.
Methods3
Lockvoid
public void Lock();Acquires the mutex, blocking the caller while another thread owns it. The same thread may acquire recursively; every successful acquisition needs its own Unlock. Release in finally. Do not hold while joining/waiting when a worker needs it to finish. Provides no timeout or CancellationToken.
TryLockbool
public bool TryLock();Attempts acquisition without a blocking wait. True means an actual acquisition, including recursive owner acquisition, and requires Unlock. False when another thread owns the mutex is not an error. Do not turn repeated TryLock calls into an endless main-thread busy loop.
boolTrue with a lock acquisition, or false without one.
Unlockvoid
public void Unlock();Releases one acquisition level held by the caller. Match each successful Lock/TryLock and call from the same thread. Not a general reset or a way to release another thread ownership. Invalid unlocking was not executed in QA.