title: arm assembly mutex strex, ldrex
body: <p>firstly thank you for watching my question and reply previously.</p>
  
  <p>I'm making an os like software on banana-pi m1.</p>
  
  <p>This platform is dual cortex a-7.</p>
  
  <p>and also i'm implementing a mutex like below.</p>
  
  <pre><code>.global lock_mutex
  lock_mutex:
      ldr     r1, =UNLOCKED
  1:  ldrex   r2, [r0]
      cmp     r2, r1
  
      wfene                           @ wfe if locked
  
      read_cp32(r1, MPIDR)            @ MPIDR (ARMv7 only)
      strexne r2, r1, [r0]            @ Trying to lock
      cmpne   r2, #1                  @ if failed to lock acquire
      beq     1b                      @ branch to before 1 label if fail to lock
  
      dmb
      bx      lr
  
  .global unlock_mutex                @ in the case of unlock, 
                                    @there's no need to check the status of lock
  unlock_mutex:
      ldr     r1, =UNLOCKED
      dmb
      str     r1, [r0]                @ clear the lock
      dmb 
      sev                             @ sending the event to other processors that is wfe status
      bx      lr  
  </code></pre>
  
  <p>in the line of "ldrex   r2, [r0]" this instruction, nothing happen and seems cpu die.</p>
  
  <p>is there any advice before use ldrex &amp; strex instruction</p>