curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Blum <dragonsi...@gmail.com>
Subject SharedValue, how does it work?
Date Wed, 01 Oct 2014 20:07:37 GMT
I've been staring at SharedValue for the last 15 minutes and I can't figure
out how it works.

Naively, I don't see how it's possible to safely implement
trySetValue(newValue).  Wouldn't it have to be compareAndSetValue(oldValue,
newValue)?

I'm imagining client code that looks like this:

byte[] currentValue = sharedValue.getValue();
byte[] newValue = operationOn(currentValue);
sharedValue.compareAndSetValue(currentValue, newValue);

The only way to write this right now (unless I'm missing something) is:

byte[] currentValue = sharedValue.getValue();
byte[] newValue = operationOn(currentValue);
sharedValue.trySetValue(newValue);

The problem is, an update can happen in between the call to getValue() and
trySetValue(), and the way the code's written, SharedValue doesn't record
read accesses, so it has no idea if any user code actually called
getValue() "recently".

Am I missing something?
Scott

Mime
View raw message