set_bit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ set_bit(9) ✨

okay bestie, welcome to the Kernel API Manual πŸ’– this is the page for set_bit, and it's honestly iconic β€” a tiny little function that flips bits in memory atomically and does not make a whole thing out of it. no cap. πŸŽ€


🌸 NAME 🌸

set_bit β€” atomically set a bit in memory πŸ’… like, one single bit. one. and it locks it down so nobody else can snatch it mid-flip. periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

void set_bit (long nr , volatile unsigned long *addr );

that's the whole vibe. void return, so don't come looking for a status code, there isn't one, she returns nothing and she's at peace with that 🫢


πŸŽ€ ARGUMENTS πŸŽ€

  • nr β€” the bit to set. which bit, bestie. which one. this is the one. ✨
  • addr β€” the address to start counting from. the starting point, the home base, the place from which we begin counting bits like the little main characters we are πŸ’œ

πŸ’… DESCRIPTION πŸ’…

so here's the tea: this is a relaxed atomic operation β€” meaning no implied memory barriers 😭 yes, you heard me. it's atomic, it sets the bit safely against concurrent modifications, but it does not sneak in any memory barriers for you. if you need ordering guarantees, that's a you problem, go look at the barrier functions, this one's just here to flip a bit and leave πŸ¦‹

and the second thing, which is lowkey the coolest part: nr may be almost arbitrarily large πŸ’€ like, go off. this function is not restricted to acting on a single-word quantity β€” it'll happily wander across multiple words in memory to reach the bit you asked for. she's flexible. she's got range. she ate. πŸ‘‘

πŸ’€ real talk though: "relaxed" and "no implied memory barriers" are load-bearing words here β€” don't go assuming ordering that this function never promised. read the caveat, bestie, i'm begging πŸ™ˆ

⭐ SEE ALSO ⭐

the whole bit-flipping friend group πŸ’– go say hi to all of them, they're all slaying in their own little atomic way 🌈


πŸ“ sign-off πŸ“

this absolute gem comes to you straight from the kernel file ./include/asm-generic/bitops, dated October 2026, and it's filed under set_bit(9) β€” remember the name, she's a legend πŸ‘‘πŸ’œ bye bestie, go set some bits responsibly!! πŸŽ€βœ¨

πŸ“¦ where this page comes from