lock
void lock(var self);
Wait until a lock can be aquired on object self
.
trylock
bool trylock(var self);
Try to acquire a lock on object self
. Returns true
on success and false
if the resource is busy.
unlock
void unlock(var self);
Release lock on object self
.
Usage
var x = new(Mutex);
lock(x); /* Lock Mutex */
print("Inside Mutex!\n");
unlock(x); /* Unlock Mutex */
Exclusive Resource
The Lock
class can be implemented by types to limit the access to them. For example this class is implemented by the Mutex
type to provide mutual exclusion across Threads.
struct Lock {
void (*lock)(var);
void (*unlock)(var);
bool (*trylock)(var);
};