Topic: arguments to atomic operations


Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Thu, 16 Sep 2010 11:37:59 CST
Raw View
restor <akrzemi1@gmail.com> writes:

>  Hi,
>  I am not too familiar with atomic operations in C++0x. I would like
> to ask a couple of questions. But perhaps the example will illustrate
> all of them already.
>
>   std::memory_order mo = x.load( std::memory_order_acquire );
>   int i = y.load( mo );

if x is std::atomic<std::memory_order> then this will work fine.

> What can be said about this example:
> 1. That while this an untypical one, it might be useful for some
> clever or hakish solutions?

I can't see any real use, though someone might be more inventive than me
on that front.

> 2. It will never work because the parameter for loads stores must be
> known at compile time?

It will work. The parameter is a normal parameter, so the library and
compiler must handle parameters that vary at runtime.

> Every example I have seen always provides literals in the parameter,
> and I came to believe that the syntax should be:
>
>  int i = y.load<std::memory_order_acquire>();

That was considered and rejected.

Anthony
--
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: restor <akrzemi1@gmail.com>
Date: Tue, 14 Sep 2010 14:49:17 CST
Raw View
 Hi,
 I am not too familiar with atomic operations in C++0x. I would like
to ask a couple of questions. But perhaps the example will illustrate
all of them already.

  std::memory_order mo = x.load( std::memory_order_acquire );
  int i = y.load( mo );

What can be said about this example:
1. That while this an untypical one, it might be useful for some
clever or hakish solutions?
2. It will never work because the parameter for loads stores must be
known at compile time?

Every example I have seen always provides literals in the parameter,
and I came to believe that the syntax should be:

 int i = y.load<std::memory_order_acquire>();

Am I right, or wrong?

Regards,
&rzej

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]