Operations on a Tuple in a Space

Put operations always overwrite (and return) whatever was stored before them in the space. But when more than one application updates the same data concurrently, it can be necessary to use “compare and set” type operations.

ActiveSpaces has two compare and set operations:
compareAndPut
This is a conditional put operation to atomically change the values associated with a key from one value to another (or fail). It takes an old tuple, and a new tuple as inputs, and returns the current tuple (meaning the new tuple if the compare was a success and the current value stored in the space otherwise). You can pass NULL as an old tuple if you want to make sure your put is an insert rather than an overwrite.
compareAndTake
This is a conditional take operation that succeeds only if the tuple that was stored in the space matches the old tuple value it takes as input.

For an example of code that works with tuples, see the documentation on the ASOperations example (ASOperations).