Lock

The __lock statement can be used to place a thread safe lock on an object. Only one thread at a time can have a lock on an object, at the end of the lock statement the lock is released.

let mylock = Object()
...
__lock mylock {
  // thread sensitive operations.
}

Limitation on Island

The __lock keyword is limited to work on Monitor classes, on Island. On the other platforms, any type can be locked on.

See Also