I am trying to implement spin lock in my code, but the spin lock that I implemented on Wikipedia leads to extremely poor performance.
int lockValue = 0; void lock() { __asm__("loop: \n\t" "movl $1, %eax \n\t" "xchg %eax, lockValue \n\t" "test %eax, %eax \n\t" "jnz loop"); }
Is there a way to improve this to make it faster?
Thank.
c inline-assembly spinlock
Jigglypuff Aug 12 2018-12-12T00: 00Z
source share