title: x86 spinlock using cmpxchg
body: <p>I'm new to using gcc inline assembly, and was wondering if, on an x86 multi-core machine, a spinlock (without race conditions) could be implemented as (using AT&amp;T syntax):</p>
  
  <pre>
  spin_lock:
  mov 0 eax
  lock cmpxchg 1 [lock_addr]
  jnz spin_lock
  ret
  
  spin_unlock:
  lock mov 0 [lock_addr]
  ret
  </pre>