Short answer: use the LOCK prefix.
EDIT: there's a race condition in there. It's also easy to fix:
Code: Select all
(1) atomically write '0' in section->status
(...) other thread makes it through steps 1..5
(2) rflags = other thread's flags
Code: Select all
(1) atomically write '0' in section->status
(...) other thread makes it through steps 1..5
(2) rflags = other thread's flags
Code: Select all
Starting with [a]=0, [b]=0
Core A:
mov rax, [a]
mov rbx, [b]
Core B:
mov rax, 1
mov [b], rax
mov [a], rax