Raw operating-system-thread lock wrapper with exclusive and shared acquisition. The wrapper owns one lock state and exposes direct lock operations.


Mutex

Methods

INIT

(--) Resets the mutex to the unlocked initial state.

lock

(--) Acquires one exclusive lock ownership.

lockShared

(--) Acquires one shared lock ownership.

tryLock

(-- locked) Attempts one exclusive acquisition without waiting. Returns TRUE when the acquisition is made and FALSE otherwise.

tryLockShared

(-- locked) Attempts one shared acquisition without waiting. Returns TRUE when the acquisition is made and FALSE otherwise.

unlock

(--) Releases one exclusive acquisition.

Preconditions

  • The current thread holds one exclusive acquisition of this mutex.

unlockShared

(--) Releases one shared acquisition.

Preconditions

  • The current thread holds one shared acquisition of this mutex.

Lock semantics


Examples

Windows lock example

"String"        use
"control.Int32" use
"windows/Mutex" use

{} Int32 {} [
  mutex: Mutex;
  locked: @mutex.tryLock;
  locked [@mutex.unlock] [] if
  @mutex.lockShared
  @mutex.unlockShared
  ("locked=" locked LF
    "shared=done" LF) printList
  0
] "main" exportFunction

Expected Output

locked=TRUE
shared=done

See also