SDL_SemPost(3)

πŸ’– SDL_SemPost β€” bestie, it's giving "unlock the semaphore" ✨

okay so this one's from the SDL API Reference manual, section 3, and honestly? it's a lil two-line function that does so much for your threads. let's get into it 🫢


🌸 NAME 🌸

SDL_SemPost β€” Unlock a semaphore. that's it. that's the whole job. iconic behavior fr fr πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include "SDL.h" #include "SDL_thread.h"

int SDL_SemPost(SDL_sem *sem);

like yes, both includes, don't @ me, that's just how the header situation is πŸ’€


✨ DESCRIPTION ✨

so SDL_SemPost unlocks the semaphore pointed to by sem and β€” this is the important part, no cap β€” atomically increments the semaphore's value. atomic. as in it all happens as one indivisible lil moment, not a "oops someone else got in between" situation. queen shit. πŸ‘‘

and the tea is: threads that were blocking on the semaphore may be scheduled after this call succeeds. may. not "definitely will immediately", just may. don't come for me, that's what the manpage says 🫠

the vibe check here: you should call SDL_SemPost after a semaphore has been locked by a successful call to one of these three besties:

  • SDL_SemWait
  • SDL_SemTryWait
  • SDL_SemWaitTimeout

lock it, do the thing, post it. that's the whole cycle. main character energy πŸ”₯


πŸŽ€ RETURN VALUE πŸŽ€

  • 0 β€” slay, it worked ✨
  • -1 β€” there was an error 😭 and listen, when it errors it leaves the semaphore unchanged. no half-done nonsense here, the semaphore stays exactly how it was.

🌈 EXAMPLES 🌈

literally one line. she's lowkey effortless:

SDL_SemPost(my_sem);

that's it. that's the example. ate and left no crumbs πŸ“


πŸ’œ SEE ALSO πŸ’œ

go read these next, bestie, they're all part of the semaphore cinematic universe:

  • SDL_CreateSemaphore
  • SDL_DestroySemaphore
  • SDL_SemWait
  • SDL_SemTryWait
  • SDL_SemWaitTimeout
  • SDL_SemValue

⚠️ friendly reminder: SDL_SemPost is the unlock, not the lock. posting a semaphore you never waited on is a whole different conversation and this page is not having it. read the SEE ALSOs before you get cute πŸ™ˆ

kisses, this page is from the SDL manual, dated Tue 11 Sep 2001, 23:00, and it lives at SDL_SemPost(3). go forth and post your semaphores responsibly πŸ§šπŸ’–πŸŒΈ

πŸ“¦ where this page comes from