This question already has an answer here:
struct test {
char hit
char delete
spinlock_t lock
}
setting test.hit = 1
without lock . If multiple threads write it, is there a chance that 'delete' field is overwritten? i.e. while hit is updated, it reads entire 8 bytes, updates the correct byte in it, but writes back the 8 bytes which could be a stale value of other members?
Assembly for similar code resulted in the following instruction
orb $0x1,(%r15)
Even though orb
is OR for 8 bit, I am not 100% sure because the register is 64 bit instead of the Lower 8 bit r15b.
Any thoughts on this?