//redundant read elimination
r = &t;
a = *r;
g()
b = *t; //replaced to a since rust compiler will assume &t is equal.
g1 = lock();
a = *g1;
drop(g1);

g2 = lock();
b = *g2;
drop(g2);

If data is inside unsafecell, rust compiler will not optimize the instructions

Send / sync for T: send (LockGuard<'s, L, T)
-> sync : only one thread will possibly access multiple thread;
drop {// guaranteed to called once
  let token = unsafe { drop :: }
  unsafe {self.lock.lock.unloc(tokeN)``} //should be called once (only when the lock has been acquired, it should be called once)
  // end of critical section
}

safety of drop function is important!!

lifetime: we should ensure the lifetime

  • lockguard vs mutable reference :

  • drop order is not decided: we need explicit scope to guarantee the drop order

  • struct { A, B; // created this way, also destroyed this way

use case of useing sync trait for lockguard?

  • additional feature