Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-11-18 06:00:08


"Philippe A. Bouchard" wrote:
[...]
> Ha ha ha... I guess I should of mentionned the Alpha with its 2 pipelines
> instead.

Alpha is dead.

>
> >> multithreaded environments. It looked like shared_count_x86_exp2.cpp
> >> coudn't run on multiple platforms.
> >
> > Yeah. refcount<> (and compilers with not-rocket-science knowledge
> > of atomics with "hoist" and "sink" barriers... and that's no matter
> > how screwed is the hardware -- compilers may reorder "as well") is
> > the way to go. I guess.
>
> Before going further with those issues I would like to specify that most of
> the time we do not need to know the content of the integer; we only need to
> know whether it is null or not atomically... the machine instructions "dec
> [counter]" immediately followed by "jne" do that.

You don't really need "portable asm" for that. C++ aside for a moment,

http://www.terekhov.de/pthread_refcount_t/draft-edits.txt

SYNOPSIS

        [THR RC] #include <pthread.h>

        int pthread_refcount_decrement(pthread_refcount_t *refcount);
        int pthread_refcount_decrement_relmsync(pthread_refcount_t *refcount);
        int pthread_refcount_decrement_acqmsync(pthread_refcount_t *refcount);
        int pthread_refcount_decrement_nomsync(pthread_refcount_t *refcount);

DESCRIPTION

        These functions shall decrement the value of the reference count
        specified by /refcount/. That is, the value 1 is subtracted from
        the value of the reference count specified by /refcount/. When
        the decremented value of the reference count is zero, the constant
        PTHREAD_REFCOUNT_DROPPED_TO_ZERO shall be returned to the calling
        thread.

        The constant PTHREAD_REFCOUNT_DROPPED_TO_ZERO is defined in
        <pthread.h> and its value shall be distinct from any other value
        returned by these functions.

        The results are undefined if these functions are called with a
        reference count which has value zero.

        The results are undefined if these functions are called with an
        uninitialized reference count.

RETURN VALUE

        If successful, these functions shall return zero or
        PTHREAD_REFCOUNT_DROPPED_TO_ZERO if the decremented value of
        the reference count is zero. Otherwise, an error number shall
        be returned to indicate the error.

ERRORS

        The pthread_refcount_decrement(),
        pthread_refcount_decrement_relmsync(),
        pthread_refcount_decrement_acqmsync() and
        pthread_refcount_decrement_nomsync() functions may fail if:

        [EINVAL]
                The object specified by /refcount/ is invalid.

        [ERANGE]
                The value of the referenced count specified by /refcount/
                is zero.

        These functions shall not return an error code of [EINTR].

You can have them as normal functions (so that you can take an
address) plus macros or intrinsic/inline function and/or whatnot.

regards,
alexander.


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