Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22006

On x64 In mutli thread scenario, can each member, of size byte or word, of a structure be set locklessly without affecting the other members [duplicate]

$
0
0
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?


Viewing all articles
Browse latest Browse all 22006

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>