Boost logo

Boost :

From: Chris Thomasson (cristom_at_[hidden])
Date: 2006-11-19 20:01:25


"Roland Schwarz" <roland.schwarz_at_[hidden]> wrote in message
news:455F548A.4010801_at_chello.at...
> Despite the obvious interest in lock free algorithms,
> we still have no atomic ops library in boost.
[...]

> I attach the prototype, which currently is for 32bit
> MSVC. I am planning to add support for gcc soon.
>
> I would be very glad if this would trigger some
> further development and fruitful discussions, which
> eventually will lead into creation of such a library.

Your missing a very important constraint, IMHO... You have no support for
loads with data-dependencies':

https://coolthreads.dev.java.net/servlets/ProjectForumMessageView?forumID=1797&messageID=11068

So your constraints should look something like this:

    enum ordering_constraint {raw, acquire, acquire_depends, release,
ordered};

I would personally do something like this:

namespace atomic {
  template<typename T> struct type;

  namespace mb {
    enum flags_e {
      storeload = 0x1,
      loadstore = 0x2,
      loadload = 0x4,
      storestore = 0x8,
      depends = 0x10,
    };
  }

  namespace meta {
    template<typename T, signed T_mb_flags> struct atomic_cas_op;
    // other atomic ops...

    // explicit specialize cas for all combinations of mb::flags_e
    // ..., ...
  }

  template<typename T>
  struct type {
    // atomic cas
    template<signed T_mb_flags>
    static bool cas(T volatile &dest, T const &cmp, T const &xchg) throw() {
      typedef meta::atomic_cas_op<T, T_mb_flags> cas_t;
      return cas_t::(dest, cmp, xchg);
    }

    // other atomic ops..., ...
  };
}

// usage
static T s_val = 0;
typedef atomic::type<T> atomic_t;

void fooinc_acquire(...) {
  do {
    T cmp = s_val;
  } while(atomic_t::cas<
       atomic::mb::storeload |
       atomic::mb::storestore
>(s_val, cmp, cmp + 1));
}

I guess I should prototype this or something...Humm...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk