No lock permission support exists.

Earlier we talked about the static permissions. In addition to these are lock permissions, which can only be used on region-managed references. Unlike static permissions, which are built-in compiler primitives, lock permissions are library-implemented.

Lock permissions are needed when we want to guarantee that only one reference can change or multiple references can read the object value at-a-time (aliasability xor mutability). This is accommodated by having borrowing acquire the lock before the underlying value can be de-referenced for read or write operation. When the borrowed reference expires, the lock is automatically released.

List of Permissions

mutex

The mutex permission enables multiple, mutable references to be shared across threads. A mutex reference itself cannot directly access or change the value it points to, except by using atomic operations.

To obtain direct access to the value, one must first obtain a borrowed reference from the mutex reference. Obtaining the borrowed reference automatically acquires a runtime lock that ensures only one reference at a time can view or modify the value the reference points to.

imm point = +gc-mutex Point(x:2, y: 3)
{
  pointref = &mut *point     // Obtain borrowed ref to unlock access to the point
	pointref.x += pointref.y   // Access to point safely protected by mutex
}

When the borrowed reference expires, so does the acquired lock.

rwlock

The rwlock permission works very much the same way as mutex, except that it allows multiple read-only borrowed references to be obtained at the same time. However, only one mutable borrowed reference may be obtained at a time.

rwcell

The rwcell permission is quite similar to rwlock, except that all its reference copies are constrained to say in a single thread. This is useful when one withes to serialize at runtime the acquisition of interior references to variant or collection values.

_