[cpp-threads] modes, interlude
Peter Dimov
pdimov at mmltd.net
Tue May 10 12:26:28 BST 2005
Alexander Terekhov wrote:
> Ok, some "lambda"-like stuff added to atomics can probably
> solve the problem of exposing LR/SC and can also be used
> to achieve efficient barriers for control-dependent stuff as
> actually required (apart from implied cchsb).
>
> Must be a peanut for Peter. ;-)
Something like
T read_modify_write( T * addr, F f )
{
for( ;; )
{
T r = *(T volatile *)addr; // nonatomic_load( addr );
if( compare_and_exchange( addr, r, f(r) ) ) return r;
}
}
It's not good for LR/SC, unfortunately, because f(r) can cause stores in the
reservation granule at the compiler's whim. LR/SC will be left for real
programmers.
void compare_and_execute( T const * addr, T value, F f );
can take advantage of cchlb/isync, but I'm not sure whether anyone will
actually use it.
More information about the cpp-threads
mailing list