globus_mutex(3)

πŸ“¦
version 18.15 Β· 6 versions
, in epel 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’– globus_mutex(3) β€” the mutual exclusion page, bestie edition πŸ’–

okay so real talk, this is the manual for globus_mutex from the globus_common library. it's a C library functions manual. we're talking mutual exclusion. locks. the whole vibe of "one thread at a time please, we're busy". ✨


🌸 NAME 🌸

globus_mutex β€” Mutual Exclusion

  • Mutual Exclusion.

(yeah they said it twice. iconic of them honestly. no notes. πŸ’…)


✨ SYNOPSIS ✨

πŸŽ€ Data Structures

  • union globus_mutex_t β€” Mutex.
  • union globus_mutexattr_t β€” Mutex attribute.
  • struct globus_rmutex_t β€” Recursive Mutex.

πŸŽ€ Typedefs

  • typedef int globus_rmutexattr_t β€” Recursive mutex attribute.

πŸŽ€ Functions

  • int globus_mutex_init (globus_mutex_t *mutex, globus_mutexattr_t *attr) β€” Initialize a mutex.
  • int globus_mutex_destroy (globus_mutex_t *mutex) β€” Destroy a mutex.
  • int globus_mutex_lock (globus_mutex_t *mutex) β€” Lock a mutex.
  • int globus_mutex_unlock (globus_mutex_t *mutex) β€” Unlock a mutex.
  • int globus_mutex_trylock (globus_mutex_t *mutex) β€” Lock a mutex if it is not locked.
  • int globus_mutexattr_init (globus_mutexattr_t *attr) β€” Initialize a mutex attribute.
  • int globus_mutexattr_destroy (globus_mutexattr_t *attr) β€” Destroy a mutex attribute.

πŸŽ€ Recursive Mutex

  • int globus_rmutex_init (globus_rmutex_t *rmutex, globus_rmutexattr_t *rattr) β€” Initialize a recursive mutex.
  • int globus_rmutex_lock (globus_rmutex_t *rmutex) β€” Lock a recursive mutex.
  • int globus_rmutex_unlock (globus_rmutex_t *rmutex) β€” Unlock a recursive mutex.
  • int globus_rmutex_destroy (globus_rmutex_t *rmutex) β€” Destroy a recursive mutex.

πŸ’« Detailed Description πŸ’«

Mutual Exclusion.

The Globus runtime includes three portable, related mutual exclusion primitives that can be used in applications and libraries. These are:

  • globus_mutex_t: a non-recursive, non-shared lock
  • globus_rmutex_t: a recursive non-shared lock
  • globus_rw_mutex_t: a reader-writer lock

three of them. a whole little lock family. found family trope fr fr 🫢


πŸ“š Function Documentation πŸ“š

int globus_mutex_destroy (globus_mutex_t * mutex)

Destroy a mutex. The globus_mutex_destroy() function destroys the mutex pointed to by its mutex parameter. After a mutex is destroyed it may no longer be used unless it is again initialized by globus_mutex_init().

🚨 bestie. Behavior is undefined if globus_mutex_destroy() is called with a pointer to a locked mutex. do not do that. i am begging. 😭

Parameters

  • mutex β€” The mutex to destroy

Returns

On success, globus_mutex_destroy() returns GLOBUS_SUCCESS. Otherwise, a non-zero implementation-specific error value is returned.


int globus_mutex_init (globus_mutex_t * mutex, globus_mutexattr_t * attr)

Initialize a mutex. The globus_mutex_init() function creates a mutex variable that can be used for synchronization. Currently, the attr parameter is ignored.

Parameters

  • mutex β€” Pointer to the mutex to initialize.
  • attr β€” Ignored.

Returns

On success, globus_mutex_init() initializes the mutex and returns GLOBUS_SUCCESS. Otherwise, a non-0 value is returned.


int globus_mutex_lock (globus_mutex_t * mutex)

Lock a mutex. The globus_mutex_lock() function locks the mutex pointed to by its mutex parameter.

Upon successful return, the thread calling globus_mutex_lock() has an exclusive lock on the resources protected by mutex. Other threads calling globus_mutex_lock() will wait until that thread later calls globus_mutex_unlock() or globus_cond_wait() with that mutex. Depending on the thread model, calling globus_mutex_lock on a mutex locked by the current thread will either return an error or result in deadlock.

πŸ’€ "return an error or result in deadlock" β€” yeah it's giving chaos, and which one you get depends on your thread model. plan accordingly.

Parameters

  • mutex β€” The mutex to lock.

Returns

On success, globus_mutex_lock() returns GLOBUS_SUCCESS. Otherwise, a non-zero implementation-specific error value is returned.


int globus_mutex_trylock (globus_mutex_t * mutex)

Lock a mutex if it is not locked. The globus_mutex_trylock() function locks the mutex pointed to by its mutex parameter if no thread has already locked the mutex. If mutex is locked, then globus_mutex_trylock() returns EBUSY and does not block the current thread or lock the mutex. Upon successful return, the thread calling globus_mutex_trylock() has an exclusive lock on the resources protected by mutex. Other threads calling globus_mutex_lock() will wait until that thread later calls globus_mutex_unlock() or globus_cond_wait() with that mutex.

✨ the "no pressure" lock. it tries, it doesn't wait around, it's emotionally available but not too available.

Parameters

  • mutex β€” The mutex to lock.

Returns

On success, globus_mutex_trylock() returns GLOBUS_SUCCESS and locks the mutex. If another thread holds the lock, globus_mutex_trylock() returns EBUSY. Otherwise, a non-zero implementation-specific error value is returned.


int globus_mutex_unlock (globus_mutex_t * mutex)

Unlock a mutex. The globus_mutex_unlock() function unlocks the mutex pointed to by its mutex parameter. Upon successful return, the thread calling globus_mutex_unlock() no longer has an exclusive lock on the resources protected by mutex. Another thread calling globus_mutex_lock() may be unblocked so that it may acquire the mutex.

🚨 Behavior is undefined if globus_mutex_unlock is called with an unlocked mutex. unlocking something that was never locked is NOT a slay, it's a hazard.

Parameters

  • mutex β€” The mutex to unlock.

Returns

On success, globus_mutex_unlock() returns GLOBUS_SUCCESS. Otherwise, a non-zero implementation-specific error value is returned.


int globus_mutexattr_destroy (globus_mutexattr_t * attr)

Destroy a mutex attribute. The globus_mutexattr_destroy() function destroys the mutex attribute structure pointed to by its attr parameter.

Parameters

  • attr β€” Attribute structure to destroy.

Returns

Upon success, globus_mutexattr_destroy() returns GLOBUS_SUCCESS and modifies the attribute pointed to by attr. If an error occurs, globus_mutexattr_destroy() returns an implementation-specific non-zero error code.


int globus_mutexattr_init (globus_mutexattr_t * attr)

Initialize a mutex attribute. The globus_mutexattr_init() function initializes the mutex attribute structure pointed to by its attr parameter. Currently there are no attribute values that can be set via this API, so there's no real use to calling this function.

πŸ’€ they really just said "this function exists and you do not need it". the honesty?? unmatched. periodt.

Parameters

  • attr β€” Attribute structure to initialize.

Returns

Upon success, globus_mutexattr_init() returns GLOBUS_SUCCESS and modifies the attribute pointed to by attr. If an error occurs, globus_mutexattr_init() returns an implementation-specific non-zero error code.


int globus_rmutex_destroy (globus_rmutex_t * rmutex)

Destroy a recursive mutex. The globus_rmutex_destroy() function destroys a recursive mutex. If the mutex is currently locked, behavior is undefined.

Parameters

  • rmutex β€” Mutex to unlock

Returns

GLOBUS_SUCCESS


int globus_rmutex_init (globus_rmutex_t * rmutex, globus_rmutexattr_t * rattr)

Initialize a recursive mutex. The globus_rmutex_init() function initializes a recursive mutex, that is, one which may be locked multiple times by a single thread without causing deadlock. πŸ¦‹

Parameters

  • rmutex β€” A pointer to the mutex to initialize
  • rattr β€” IGNORED

Returns

On success, globus_rmutex_init() initializes the mutex and returns GLOBUS_SUCCESS; otherwise, it returns a non-zero error code.


int globus_rmutex_lock (globus_rmutex_t * rmutex)

Lock a recursive mutex. The globus_rmutex_lock() function acquires the lock controlled by rmutex. This may be called multiple times in a single thread without causing deadlock, provided that a call to globus_rmutex_unlock() is called the same number of times as globus_rmutex_lock(). Once acquired, all other threads calling this function will be blocked until the mutex is completely unlocked.

🧚 the "same number of times" rule is the whole ballgame. lock 3 times, unlock 3 times. keep the receipts.

Parameters

  • rmutex β€” A pointer to the mutex to lock

Returns

On success, globus_rmutex_init() increases the lock level for the mutex, blocks other threads trying to acquire the same mutex, and returns GLOBUS_SUCCESS; otherwise, it returns a non-zero error code.


int globus_rmutex_unlock (globus_rmutex_t * rmutex)

Unlock a recursive mutex. The globus_rmutex_unlock() function decrements the lock count for the lock pointed to by rmutex. If the lock count is reduced to zero, it also unblocks a thread which is trying to acquire the lock if there is one.

Parameters

  • rmutex β€” Mutex to unlock

Returns

GLOBUS_SUCCESS


🌈 Author 🌈

Generated automatically by Doxygen for globus_common from the source code.


okay that's the whole page bestie, you ate it, you're a locks girlie now πŸ‘‘ this was globus_common, Version 18.15 β€” go forth and synchronize responsibly πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ’