__author__="Brock"
__date__ ="$Feb 19, 2011 11:52:30 AM$"

import threading

class CompareAndSwapRegister:
    "CompareAndSwap class"
    def __init__(self):
        self.value = 0
        self.vallock = threading.Lock()
    def CompareAndSwap(self, oldval, newval):
        # some syntax problem with with...
        try:
            self.vallock.acquire()
            presval = self.value
            if (presval == oldval):
                self.value = newval
        finally:
            self.vallock.release()
        return presval
    def __str__(self):
        return str(self.value)

