[cpp-threads] A question about N2153

Alexander Terekhov alexander.terekhov at gmail.com
Wed Jan 17 19:47:00 GMT 2007


On 1/17/07, Peter Dimov <pdimov at mmltd.net> wrote:
> What is the reference implementation of acquire_fence for x86, SPARC RMO,
> PowerPC, IA-64? I'm guessing (no op), #LoadLoad | #LoadStore, lwsync, mf.
>
> If we take the example:
>
> if( fetchadd_release( &ref_count, -1 ) == 1 ) // old value
> {
>    acquire_fence();
>    destroy_object();
> }

This example is driving at std::tr1::shared_ptr's "strong" count
decrement (a decrement that is a release when the new value is nonzero
and an acquire when the new value is zero with a requirement to
actually store 0 for increment_if_not_zero()  std::tr1::weak_ptr's
logic to work).

>
> this is fine on x86/SPARC. On PowerPC, however, the most efficient

As you surely recall, the most efficient on PowerPC is the following:

asm long atomic_decrement_strong( register long * pw ) {

    // Peter's state machine

    loop0:

      <load-reserved>
      <add -1>
      <branch if zero to loop0_acquire>

      {lw}sync

    loop1:

      <store-conditional>
      <branch if !failed to done>

    loop2:

      <load-reserved>
      <add -1>
      <branch if !zero to loop1>
      <store-conditional>
      <branch if failed to loop2 else to acquire>

    loop0_acquire:

      <store-conditional>
      <branch if failed to loop0>

    acquire:

      isync

    done:

      <...>
}

(And we can even get rid of acquire/isync in specialization for
managed objects that are immutable or have trivial dtors.)

regards,
alexander.



More information about the cpp-threads mailing list