assembly - What is the scope of lock prefix? -
it said assembly instruction prefixed "lock" atomic. want know if "lock" can affect 1 assembly instruction; assembly instruction not atomic?
here example of atomic function in linux kernel:
static __inline__ int atomic_sub_and_test(int i, atomic_t *v) { unsigned char c; __asm__ __volatile__( lock "subl %2,%0; sete %1" :"=m" (v->counter), "=qm" (c) :"ir" (i), "m" (v->counter) : "memory"); return c; }
in example can subl , sete interrupted?
the lock prefix affects single instruction.
instructions stop being atomic when modify memory shared between several cpus. modifications involve reading memory operand, performing operation on (e.g. and, xor, inc, etc) , writing not seen atomic other cpus. lock prefix "locks" memory location, 3 steps (read, modify, write) one, i.e. other cpus can observe before , after locked instruction.
see official cpu documentation intel or amd.
edit: in newly added example neither of instructions can interrupted, if we're talking interrupts. interrupts occur between entire instructions. lock prefix makes sub
instruction atomic. sete
instruction not intended atomic, it's there transform zf
flag 0 or non-zero integer value.
Comments
Post a Comment