mutex_unlock


mutex_unlock(m, @optional mn = false, timeout = false)
      

Unlocks the mutex m by making it unlocked/not-abandoned. It is not an error to unlock an unlocked mutex and a mutex that is owned by any task. If supplied, mn must be a monitor object. The current task is blocked and added to the monitor before unlocking the mutex; the task can unblock at any time but no later than when an appropriate call to monitor_notify or monitor_broadcast is performed, and no later than the timeout (if timeout is supplied). If there are tasks waiting to lock this mutex, the scheduler selects a task, the mutex becomes locked/owned or locked/not-owned, and the task is unblocked. Mutex_unlock returns false when the timeout is reached, otherwise it returns true.

If provided, timeout should be an exact or inexact real number representing a relative time in seconds from the moment mutex_unlock was called.

Examples:


// updating shared state without a data race:          
let x = 0
let mx = mutex()

function incx()
{ mutex_lock(mx)
  x = inc(x)
  mutex_unlock(mx) }

!incx()
!incx()
x
// 2          
      

Also see:

mutex
mutex_unlock


Core Module Index | Contents