concurrency - Requirements for an MRSW Atomic Register -


the following code sample "the art of multiprocessor programming" chapter 4. book understand need fulfill 3 conditions classify register atomic register.

  1. read on register should provide value written.
  2. read cannot return value distant past.
  3. if there 2 consecutive reads same thread, later read cannot return value older previous read operation.
1 public class atomicsrswregister<t> implements register<t> { 2     threadlocal<long> laststamp; 3     threadlocal<stampedvalue<t>> lastread; 4     stampedvalue<t> r_value; // regular srsw timestamp-value pair 5     public atomicsrswregister(t init) { 6         r_value = new stampedvalue<t>(init); 7         laststamp = new threadlocal<long>() { 8             protected long initialvalue() { return 0; }; 9         }; 10        lastread = new threadlocal<stampedvalue<t>>() { 11            protected stampedvalue<t> initialvalue() { return r_value; }; 12        }; 13    } 14    public t read() { 15        stampedvalue<t> value = r_value; 16        stampedvalue<t> last = lastread.get(); 17        stampedvalue<t> result = stampedvalue.max(value, last); 18        lastread.set(result); 19        return result.value; 20    } 21    public void write(t v) { 22        long stamp = laststamp.get() + 1; 23        r_value = new stampedvalue(stamp, v); 24        laststamp.set(stamp); 25    } 26 } 

stampedvalue class 2 elements, counter , value. counter tells version of value. each time value modified, associated counter incremented.

for code above, have condition violated? request show mrsw system in conditions violated.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -