[concurrency-interest] Lock-free implementation of min including assignment

Martin Buchholz martinrb at google.com
Wed Jan 18 15:23:55 EST 2012


On Wed, Jan 18, 2012 at 06:16, Markus Jevring <m.jevring at iontrading.com>wrote:

> If it does, I'm surprised it's not plastered all over the internet.


We've written something here:
http://g.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/atomic/package-info.java?view=co

 * <p>It is straightforward to define new utility functions that, like
 * {@code getAndIncrement}, apply a function to a value atomically.
 * For example, given some transformation
 * <pre> {@code long transform(long input)}</pre>
 *
 * write your utility method as follows:
 *  <pre> {@code
 * long getAndTransform(AtomicLong var) {
 *   while (true) {
 *     long current = var.get();
 *     long next = transform(current);
 *     if (var.compareAndSet(current, next))
 *         return current;
 *   }
 * }}</pre>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120118/b27fd8bd/attachment.html>


More information about the Concurrency-interest mailing list