From: Robert Morris Date: Thu, 8 Sep 2016 18:45:20 +0000 (-0400) Subject: use asm() for lock release, not a C assignment X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=34c2efc1d063f4b366c1017c174d117cc96eb990;p=cs3210-lab0.git use asm() for lock release, not a C assignment --- diff --git a/spinlock.c b/spinlock.c index bf863ef..7b372ef 100644 --- a/spinlock.c +++ b/spinlock.c @@ -59,8 +59,10 @@ release(struct spinlock *lk) // stores; __sync_synchronize() tells them both to not re-order. __sync_synchronize(); - // Release the lock. - lk->locked = 0; + // Release the lock, equivalent to lk->locked = 0. + // This code can't use a C assignment, since it might + // not be atomic. + asm volatile("movl $0, %0" : "+m" (lk->locked) : ); popcli(); }