Hi Alvise, On Thu, May 26, 2016 at 12:35 PM, Alvise Rigo <a.r...@virtualopensystems.com> wrote: > Add tcg_exclusive_{lock,unlock}() functions that will be used for making > the emulation of LL and SC instructions thread safe. > > Signed-off-by: Alvise Rigo <a.r...@virtualopensystems.com>
<snip> > +__thread bool cpu_have_exclusive_lock; > +QemuSpin cpu_exclusive_lock; > +inline void tcg_exclusive_lock(void) > +{ > + if (!cpu_have_exclusive_lock) { > + qemu_spin_lock(&cpu_exclusive_lock); > + cpu_have_exclusive_lock = true; > + } > +} > + > +inline void tcg_exclusive_unlock(void) > +{ > + if (cpu_have_exclusive_lock) { > + cpu_have_exclusive_lock = false; > + qemu_spin_unlock(&cpu_exclusive_lock); > + } > +} I think the unlock() here should have an assert if cpu_have_exclusive_lock is false. From what I can see, a thread should either take the exclusive lock or wait spinning for it in lock(). So unlock() should always see cpu_have_exclusive_lock as true. It is a good place to find locking bugs. -- Pranith