digitalmars.D.learn - GetAndSet function (corresponding to cas function)
- Adrian Mercieca (4/4) Dec 25 2011 Hi folks,
- Mike Wey (5/9) Dec 25 2011 core.atomic.cas
- Adrian Mercieca (4/15) Dec 25 2011 I know of the cas function in D.
- Adrian Mercieca (8/8) Dec 26 2011 Hi folks,
- Andrew Wiley (11/20) Dec 26 2011 ---
- Adrian Mercieca (5/33) Dec 27 2011 Hi Andrew,
- Adrian Mercieca (3/3) Dec 27 2011 Hi Andrew,
- Jonathan M Davis (5/15) Dec 26 2011 If it's not in core.atomic, then probably not. It has atomicLoad and
- Andrew Wiley (14/28) Dec 26 2011 getAndSet can easily be implemented as a utility method using cas and
Hi folks, Is there a GetAndSet function (corresponding to cas (compare and set) function) in D? Thanks.
Dec 25 2011
On 12/25/2011 09:25 AM, Adrian Mercieca wrote:Hi folks, Is there a GetAndSet function (corresponding to cas (compare and set) function) in D? Thanks.core.atomic.cas http://dlang.org/phobos/core_atomic.html#cas -- Mike Wey
Dec 25 2011
On Sun, 25 Dec 2011 13:37:32 +0100, Mike Wey wrote:On 12/25/2011 09:25 AM, Adrian Mercieca wrote:I know of the cas function in D. I was asking if there was a getAndSet function. Tks.Hi folks, Is there a GetAndSet function (corresponding to cas (compare and set) function) in D? Thanks.core.atomic.cas http://dlang.org/phobos/core_atomic.html#cas
Dec 25 2011
Hi folks, Would anyone answer me on this please? To clarify, in Java there is are getAndSet methods on Atomic type objects (along with compareAndSet). I know that in D there is the cas function (equivalent to Java's compareAndSet); is there an equivalent D function for Java's getAndSet please? Thanks.
Dec 26 2011
On Mon, Dec 26, 2011 at 2:34 PM, Adrian Mercieca <amercieca gmail.com> wrote:Hi folks, Would anyone answer me on this please? To clarify, in Java there is are getAndSet methods on Atomic type objects (along with compareAndSet). I know that in D there is the cas function (equivalent to Java's compareAndSet); is there an equivalent D function for Java's getAndSet please? Thanks.From Java:--- public final boolean getAndSet(boolean newValue) { for (;;) { boolean current = get(); if (compareAndSet(current, newValue)) return current; } } --- getAndSet is just a wrapped version of compareAndSet.
Dec 26 2011
On Mon, 26 Dec 2011 15:06:57 -0600, Andrew Wiley wrote:On Mon, Dec 26, 2011 at 2:34 PM, Adrian Mercieca <amercieca gmail.com> wrote:Hi Andrew, It is indeed; should have thought of that. Anyway, thanks for pointing it out. Regards.Hi folks, Would anyone answer me on this please? To clarify, in Java there is are getAndSet methods on Atomic type objects (along with compareAndSet). I know that in D there is the cas function (equivalent to Java's compareAndSet); is there an equivalent D function for Java's getAndSet please? Thanks.From Java:--- public final boolean getAndSet(boolean newValue) { for (;;) { boolean current = get(); if (compareAndSet(current, newValue)) return current; } } --- getAndSet is just a wrapped version of compareAndSet.
Dec 27 2011
Hi Andrew, Actually, what would be the equivalent of the 'get' function in D? Thanks.
Dec 27 2011
On Monday, December 26, 2011 20:34:39 Adrian Mercieca wrote:Hi folks, Would anyone answer me on this please? To clarify, in Java there is are getAndSet methods on Atomic type objects (along with compareAndSet). I know that in D there is the cas function (equivalent to Java's compareAndSet); is there an equivalent D function for Java's getAndSet please?If it's not in core.atomic, then probably not. It has atomicLoad and atomicStore, but I don't see anything that tries to combine the two, assuming that that's what you want be getAndSet. - Jonathan M Davis
Dec 26 2011
On Mon, Dec 26, 2011 at 4:05 PM, Jonathan M Davis <jmdavisProg gmx.com> wrote:On Monday, December 26, 2011 20:34:39 Adrian Mercieca wrote:getAndSet can easily be implemented as a utility method using cas and atomicLoad. It's not a primitive atomic operation, it's just a convenience function. T getAndSet(T)(shared(T)* location, T newValue) { while(1) { auto current = atomicLoad(*location); if(cas(location, current, newValue)) return current; } } Someone who knows more about the options to atomicLoad could probably make this faster, but because we're using cas, it's guaranteed to be correct.Hi folks, Would anyone answer me on this please? To clarify, in Java there is are getAndSet methods on Atomic type objects (along with compareAndSet). I know that in D there is the cas function (equivalent to Java's compareAndSet); is there an equivalent D function for Java's getAndSet please?If it's not in core.atomic, then probably not. It has atomicLoad and atomicStore, but I don't see anything that tries to combine the two, assuming that that's what you want be getAndSet.
Dec 26 2011