Example: MCS non-NUMA Pseudocode - Google Groups

3 downloads 112 Views 12KB Size Report
public void unlock() {. QNode* me = this.myNode; if (atomic_load(me.next) == null) { if (current.compare_exchange(me, nu
Example: MCS non-NUMA Pseudocode struct QNode { QNode* next } QNode* current; class Thread { QNode* myNode; public void lock() { QNode* me = this.myNode; QNode* prev = atomic_exchange(¤t, me); if (prev != null) { atomic_store(prev.next, me); while (atomic_load(prev.next)) {} } }

6A

Example: MCS non-NUMA Pseudocode unlock()

public void unlock() { QNode* me = this.myNode; if (atomic_load(me.next) == null) { if (current.compare_exchange(me, null)) return; // I am last, next should be null // wait for next thread to update .next while (atomic_load(me.next) == null) {} } atomic_store(me.next, null); } }

7A