Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

How to use acquire and release for reordering? #70

Closed
BoSamothrace opened this issue Jun 8, 2019 · 1 comment
Closed

How to use acquire and release for reordering? #70

BoSamothrace opened this issue Jun 8, 2019 · 1 comment

Comments

@BoSamothrace
Copy link

I don't know how to use load and store yet.

  1. What are the "load" and "store" meaning in the lecture note "X.load(acquire); X.store(42,release)"? Are they the instructions on the register?

  2. Could I use it as
    Thread A: X=42; F.load(acquire); F.store(1,release);
    Thread B: do { f=F } while(f==0);
 assert(X==42);

or Do I have to use the acquire and release with spinlock? Like:
Thread A: X=42; spinlock_lock(&lock); F=1; spinklock_unlock(&lock)

Thread B: do { spinlock_lock(&lock); f=F; spinklock_unlock(&lock)
 } while(f==0); assert(X==42)

@jeehoonkang
Copy link
Member

jeehoonkang commented Jun 9, 2019

  1. Load from the location X, and store to the location X. They are instructions on the memory location represented by X.

  2. The following is also correct:

    (thread A) X = 42; F.store(1, release);
    (thread B) do { f = F.load(acquire) } while (f == 0); assert(X == 42);
    

    But in the slide, I intentionally used lock to make a point: when in doubt, protect all concurrent accesses with locks. I will not ask questions on the above code in the exam, because I didn't teach it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants