multithreading - Atomic operations on memory mapped files -
i'm using memory mapped file , need use atomic store on go. use storeuint64() if working on regularly allocated memory. however, i'm not sure how atomic operations work on memory mapped files.
is safe use storeuint64() on memory mapped files?
it's safe. example, on amd64, uses xchg instruction.
func storeuint64(addr *uint64, val uint64)
storeuint64atomically storesval*addr.
text ·storeuint64(sb),nosplit,$0-16 movq addr+0(fp), bp movq val+8(fp), ax xchgq ax, 0(bp) ret intel 64 , ia-32 architectures software developer's manual
xchg—exchange register/memory registerdescription
exchanges contents of destination (first) , source (second) operands. operands can 2 general-purpose registers or register , memory location. if memory operand referenced, processor’s locking protocol automatically implemented duration of exchange operation, regardless of presence or absence of lock prefix or of value of iopl.
Comments
Post a Comment