Skip to content

Instantly share code, notes, and snippets.

@rystsov
Last active September 8, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rystsov/155504eea63e19f040de to your computer and use it in GitHub Desktop.
Save rystsov/155504eea63e19f040de to your computer and use it in GitHub Desktop.
Accepted = namedtuple('Accepted', ['n', 'val'])
class Variable:
def __init__(self, nodes, q):
self.q = q
self.nodes = nodes
self.promise = 0
self.accepted = Accepted(0,None)
self.mem = Mem() # we don't persist self.mem and keep it in memory
self.mem.era = 0 # current era
self.mem.ops = 0 # number of active _read_write_read started in current era
self.mem.old_ops = 0 # number of active _read_write_read started in previous era
self.mem.lock = Condition() # serializes access to self.mem
@synchronized
def prepare(self, n):
if self.promise.n < n:
self.promise = n
return self.accepted
return Conflict(promise=self.promise)
@synchronized
def accept(self, n, val):
if self.promise == n:
self.accepted = Accepted(n, val)
return OK()
return Conflict(promise=self.promise)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment