[cpp-threads] atomic operations package

Alexander Terekhov alexander.terekhov at gmail.com
Thu Aug 25 15:40:34 BST 2005


On 8/25/05, Peter Dimov <pdimov at mmltd.net> wrote:
> Alexander Terekhov wrote:
> > On 8/23/05, Peter Dimov <pdimov at mmltd.net> wrote:
> > [...]
> >> The C people would never accept the <> syntax. They hate templates
> >> with a passion. :-)
> >
> > Why not simply give a bunch of macros to templates haters?
> >
> > __STDC_ATOMIC_SCALAR(int, v);
> 
> This doesn't work, I may need to be able to express the type atomic<int>
> outside of a declaration.
> 
>     __STD_ATOMIC(int) v;
> 
> I'm still with
> 
>     int v;

I'm not. 

__STD_ATOMIC(char) v[2];

vs

char v[2];

the later may not provide proper isolation, to begin with.

It also makes it way to easy (error-prone) to code non-atomic ops:

int v;
... 
v++; // <-- intentional or bug?

vs

__STD_ATOMIC(int) v;
... 
__STD_EXCLUSIVE_ACCESS(v)++; // properly labeled


> 
> >> atomic_load( &v, msync_acq )
> >
> > __STDC_ATOMIC_LOAD(v, __STDC_MSYNC_ACQ);
> 
> Merely an uglier version of the line above. Why is this an improvement?

Because it allows generic programing using preprocessor. ;-)

regards,
alexander.




More information about the cpp-threads mailing list