title: Why we need lock prefix before CMPXCHG
body: <p>why do we need lock prefix before CMPXCHG in intel architecture.
  please see for reference
  <a href="http://courses.engr.illinois.edu/ece390/archive/spr2002/books/labmanual/inst-ref-cmpxchg.html" rel="nofollow">http://courses.engr.illinois.edu/ece390/archive/spr2002/books/labmanual/inst-ref-cmpxchg.html</a></p>
  
  <p>what i am not sure what are the consequences if don,t use lock. because between loading the value into eax and exceuting LOCK CMPXCHG the value could be changed irrespective of the lock prefix because loading value into  eax and LOCK CMPXCHG are two instructions. </p>
  
  <p>Mean to say if i dont use CMPXCHG the worst thing could happen is that i have to spin again.</p>