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

    func storeuint64(addr *uint64, val uint64) 

storeuint64 atomically stores val *addr.

src/sync/atomic/asm_amd64.s;

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 register

description

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

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -