10.4 Thread synchronisation
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Multithreaded applications
        • Thread synchronisation
          • mutex_create/1
          • mutex_create/2
          • mutex_destroy/1
          • with_mutex/2
          • mutex_lock/1
          • mutex_trylock/1
          • mutex_unlock/1
          • mutex_unlock_all/0
          • mutex_property/2
    • Packages
Availability:built-in
with_mutex(+MutexId, :Goal)
Execute Goal while holding MutexId. If Goal leaves choice points, these are destroyed (as in once/1). The mutex is unlocked regardless of whether Goal succeeds, fails or raises an exception. An exception thrown by Goal is re-thrown after the mutex has been successfully unlocked. See also mutex_create/1 and setup_call_cleanup/3.

Although described in the thread section, this predicate is also available in the single-threaded version, where it behaves simply as once/1.