al_lock_mutex(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

al_lock_mutex β€” Allegro 5 API πŸŽ€

okay so bestie, this is the one that grabs the lock, like literally claims it, no cap πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro5/allegro.h>

void al_lock_mutex(ALLEGRO_MUTEX *mutex)

πŸ’– DESCRIPTION πŸ’–

So what this does is acquire the lock on mutex. That's it, that's the whole vibe. πŸ”₯

Now here's the tea: if that mutex is already locked by another thread, this call is gonna block β€” like it just sits there waiting, being patient, until the mutex becomes available and locked. Then it does its thing. ⭐

But bestie, if the mutex is already locked by the calling thread? πŸ‘€ That's where it gets spicy, because the behaviour depends on how the mutex was created:

  • if it came from al_create_mutex(3alleg5) β€” the behaviour is undefined, and the most likely behaviour is deadlock πŸ’€ (yeah. not the cute kind.)
  • if it came from al_create_mutex_recursive(3alleg5) β€” then the count in the mutex gets incremented and the call returns immediately. slay. πŸ‘‘
undefined behaviour is not a vibe. if you're using a plain mutex, don't lock it twice from the same thread. periodt. πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹

also, real talk: we don't yet have al_mutex_trylock. it's giving "not yet invented" 😭 so don't go looking for it. 🌈


mwah πŸ’œ this lil page came straight out of the Allegro reference manual, and it's the al_lock_mutex(3alleg5) page. go forth and lock responsibly, bestie 🫢✨

πŸ“¦ where this page comes from