Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-02-10 15:36:11


Peter Dimov wrote:
>
> Alexander Terekhov wrote:
> [...]
> > bool acquire_strong_from_weak() {
> > int status = pthread_refcount_enroll_one(&strong_count); //
> [...]
> > Or am I just missing and/or misunderstanding something?
>
> You are missing the fact that nobody (even Google) has a clue as to what
> pthread_refcount_enroll_one is/does. ;-)

Ah. Sorry. Basically it's a rather simple "CAS"- ["compare-and-swap"]
or "LL/SC"- [load-locked/store-conditional] based operation; in terms
of proposed Java-atomics(*): <behaviorally, error checking aside>

extern "C" int pthread_refcount_enroll_one(pthread_refcount_t* rc) {
  size_t value;
  do {
    if ( 0 == (value = rc->__get()) )
      return PTHREAD_REFCOUNT_DROPPED_TO_ZERO;
  } while (!rc->__attemptUpdate(value, value + 1));
  return 0;
}

regards,
alexander.

(*) [but WITHOUT any memory synchronization/barriers for _enroll_*()]
    http://groups.google.com/groups?threadm=3D8B257C.4D8D58F%40web.de
    (Subject: Re: rwlock using pthread_cond (or Win32 events) [last
    link retired; stuff is available here: <http://tinyurl.com/5mmj>])


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