shadow:natives

Class Mutex

Parent class

shadow:standard@Object

immutable locked class Mutex

Class Mutex is an implementation of Mutual-Exclusion in Shadow. This implementation allows nested locks, which can be useful in some scenarios, such as with recursive methods.

Author

Claude Abounegm

See Also

Create Summary

Modifiers Return Types Method and Description
public () create()

Initializes a new Mutex.

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

Modifiers Return Types Method and Description
public readonly (Mutex) copy(AddressMap addresses)
public readonly locked () free()

Frees the resources allocated by this Mutex.

public readonly locked () lock()

Attempts to lock this mutex.

public readonly locked () unlock()

Attempts to unlock this mutex.

Create Detail

create

public create() => ()

Initializes a new Mutex.

Destroy Detail

destroy

public destroy() => ()

Method Detail

copy

public readonly copy(AddressMap addresses) => (Mutex)

free

public readonly locked free() => ()

Frees the resources allocated by this Mutex.

Throws

MutexException - if the Mutex is locked by another thread.

lock

public readonly locked lock() => ()

Attempts to lock this mutex. If the mutex is already owned by another thread, this method blocks until the mutex becomes available. If the current thread already owns this mutex, this method will simply increase the counter. The mutex should be unlocked the same number of times it was locked.

Throws

FreedResourceException - if the mutex has been freed.

unlock

public readonly locked unlock() => ()

Attempts to unlock this mutex. If the mutex has been locked multiple times by this thread, this method simply decreases the counter. This mutex is unlocked when an corresponding unlock has been called for each lock. i.e. If lock() was called twice, unlock() will unlock the mutex on its second call.

Throws

MutexException - if this mutex is not owned by this thread.

FreedResourceException - if the mutex has been freed.