set_bit(9)
β¨ 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 β
- Kernel file
./include/asm-generic/bitops/instrumented-atomic.hβ like, the actual source, iykyk π§ clear_bit(9)change_bit(9)test_and_set_bit(9)test_and_clear_bit(9)test_and_change_bit(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms