down_trylock(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… down_trylock(9) β€” bestie edition

okay so you opened the Kernel API Manual page for down_trylock(9) and honestly? this one is short and sweet and the plot twist is at the end, so stay with me 🫢


✨ NAME ✨

down_trylock β€” try to grab the semaphore, but like… without waiting. no queuing, no standing in line, no "give me one sec". it's giving attempt and dip πŸ’¨


🌸 SYNOPSIS 🌸

int down_trylock (struct semaphore *sem );

πŸŽ€ ARGUMENTS πŸŽ€

  • sem β€” the semaphore you're trying to acquire. that's it. that's the whole argument list. iconic minimalism.

πŸ¦‹ DESCRIPTION πŸ¦‹

so the whole bit here is: try to acquire the semaphore atomically. like, one clean indivisible moment, no weird half-states, no "almost got it" energy.

what does it return? literally just two possibilities:

  • returns 0 if the semaphore got acquired successfully β€” slay, you got it πŸ‘‘
  • returns 1 if it cannot be acquired β€” no luck, moving on πŸ™ˆ

that's it. it does not wait. it does not block. it just checks and reports back like a very honest friend.


⚠️ NOTE ⚠️

okay so this is the part where you need to actually pay attention bestie, because the return value is inverted from both spin_trylock and mutex_trylock πŸ’€

like, 0 means success and 1 means failure here. yes, really. no cap. be so careful about this when you're converting code, because that flip will absolutely bite you.

also, unlike mutex_trylock, this function can be used from interrupt context, and the semaphore can be released by any task or interrupt. so it's way more flexible about who does the freeing. very main character energy, very "i don't gatekeep" 🌈


πŸ”₯ SEE ALSO πŸ”₯


k that's the whole page, you're welcome πŸ’– this guide lives in the ./kernel/locking directory, dated October 2026, and if you made it this far β€” yes you get a gold star ⭐ and the title down_trylock(9), which is also just the name of the function, because manpages love a callback πŸŽ€

πŸ“¦ where this page comes from