Interface
interface IReentrantMutex
public interface IReentrantMutex
Description: Provides an interface for implementing reentrant mutex.
Note:
When implementing this interface, you must ensure that the underlying mutex supports nested locks. Otherwise, a deadlock occurs during nesting.
func lock()
func lock(): Unit
Description: Locks a mutex.
If a mutex is locked, the current thread is blocked.
func tryLock()
func tryLock(): Bool
Description: Tries to lock a mutex.
Returns:
- Bool: If a mutex is already locked, false is returned. Otherwise, the mutex is locked and true is returned.
func unlock()
func unlock(): Unit
Description: Unlocks a mutex.
If a mutex is repeatedly locked for N times, this function needs to be called for N times to unlock the mutex. Once the mutex is completely unlocked, if other threads are blocked on the mutex, one of the threads is awakened.
Throws:
- IllegalSynchronizationStateException: If the current thread does not hold the mutex, this exception is thrown.