[cpp-threads] modes, interlude
Alexander Terekhov
alexander.terekhov at gmail.com
Tue May 10 14:09:34 BST 2005
On 5/10/05, Peter Dimov <pdimov at mmltd.net> wrote:
> 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.
Well. On Power, the processor holding reservation will not lose
reservation if it executes store instruction (other than a stwcx
or stdcx) in the middle.
Register spills in the middle are "dangerous" only with respect
to livelocks on Power. With lambda-like stuff for LR/SC I meant
ability to express "more complicated sequence" from B.3 List
Insertion in Book II.
regards,
alexander.
More information about the cpp-threads
mailing list