[cpp-threads] A question about N2153
Peter Dimov
pdimov at mmltd.net
Wed Jan 17 22:35:36 GMT 2007
Alexander Terekhov wrote:
> On 1/17/07, Peter Dimov <pdimov at mmltd.net> wrote:
>> if( fetchadd_release( &ref_count, -1 ) == 1 ) // old value
>> {
>> acquire_fence();
>> destroy_object();
>> }
[...]
>> this is fine on x86/SPARC. On PowerPC, however, the most efficient
>
> As you surely recall, the most efficient on PowerPC is the following:
[...]
Right. I was talking about the most efficient PPC rendition of the above
"portable" example in order to understand the semantics of N2153
acquire_fence. Imagine for the sake of discussion that the programmer
doesn't maintain platform-specific versions and just uses this code
everywhere.
The state machine in the N2153 notation might be expressed as something
along the lines of
bool r = true;
long v = load_raw( &count );
do
{
if( r && v != 1 )
{
release_fence(); // lwsync
r = false;
}
} while( !compare_and_exchange_raw( &count, &v, v - 1 ) );
if( v == 1 )
{
acquire_fence(); // need isync here for max efficiency
destroy_object();
}
but this is platform-specific since it won't be optimal on IA-whatever. It's
still an interesting case to analyze on the four architectures, of course,
but let's proceed one thing at a time. :-)
More information about the cpp-threads
mailing list