Interest in atomic library?

In this day and age, running our C++ programs off fossil fuels makes a dangerous contribution to global warming and requires purchase of carbon offsets for ethical programming. Thus I think it's time for a Boost atomic power library. Oops, sorrry, wrong meaning of atomic. What would people think of an atomic integer library, along the lines of Linux's asm/atomic.h? I'd propose a class atomic<T> implementing operations like atomic read (implicit conversion to T), atomic set (assignment from T), and compare-and-exchange. For integral types it would support atomic add and return result (operator+=), atomic subtract and return result (operator-=), atomic increment and return result (prefix operator++), and atomic decrement and return result (prefix operator--). For arbitrary architectures or unhandled types of T, there would be a naive implementation using a mutex. On supported architectures there would be specializations for integral T types, using assembly to implement more efficient atomic operations. This assembly could pretty much just be borrowed from the Linux asm/atomic.h headers. What do people think? I see pros: + Cross-platform efficient atomic operations for efficient threaded apps. I see cons: - Hard to predict whether your atomic ops will be efficient (no specialization for your architecture/T). - Some architectures may implement different atomic ops, making the above ops not the most efficient. I think the pros outweight the cons. I'd personally much rather use a Boost.atomic library than asm/atomic.h. Seth

Are you suggesting an implementation of std::atomic<T>? --Jeffrey Bosboom

On Tue, Apr 21, 2009 at 17:33, <jbosboom@uci.edu> wrote:
Are you suggesting an implementation of std::atomic<T>?
I wasn't suggesting that, since I'd never heard of std::atomic<T>. Reading the GNU libstdc++ docs, it appears atomic<T> is a C++ 200x feature, and is only implemented in the latest release (4.4) of libstdc++. (I happen to be using release 4.1.) Anyway, now that I know about atomic<T>, I suppose I am suggesting an implementation of it. It looks like exactly what I was describing, only much more complete and fully thought-out. I'm not sure how useful it would be to implement such a thing in boost as C++0x is headed into compilers, but there will certainly be plenty of older compilers and standard libraries out there which could benefit from it for quite some time. In any case, I'm glad to see that better minds than mine have already solved my problem! Seth

On Tue, Apr 21, 2009 at 17:33, <jbosboom@uci.edu> wrote:
Are you suggesting an implementation of std::atomic<T>?
I wasn't suggesting that, since I'd never heard of std::atomic<T>. Reading the GNU libstdc++ docs, it appears atomic<T> is a C++ 200x feature, and is only implemented in the latest release (4.4) of libstdc++. (I happen to be using release 4.1.)
Anyway, now that I know about atomic<T>, I suppose I am suggesting an implementation of it. It looks like exactly what I was describing, only much more complete and fully thought-out. I'm not sure how useful it would be to implement such a thing in boost as C++0x is headed into compilers, but there will certainly be plenty of older compilers and standard libraries out there which could benefit from it for quite some time.
In any case, I'm glad to see that better minds than mine have already solved my problem!
Seth _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I didn't mean it to mock your lack of knowledge; I meant it in terms of "I'd like to use this future feature today; is that what you're planning?" --Jeffrey Bosboom

On Wed, Apr 22, 2009 at 4:14 PM, Seth LaForge <sethml@ofb.net> wrote:
On Tue, Apr 21, 2009 at 17:33, <jbosboom@uci.edu> wrote:
Are you suggesting an implementation of std::atomic<T>?
I wasn't suggesting that, since I'd never heard of std::atomic<T>. Reading the GNU libstdc++ docs, it appears atomic<T> is a C++ 200x feature, and is only implemented in the latest release (4.4) of libstdc++. (I happen to be using release 4.1.)
The best reference is the current C++ Standard Working Paper. Go to http://www.open-std.org/jtc1/sc22/wg21/ and select "Current C++ Standard Working Paper" in the "Other information" section. The original proposal is available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html, and it is very helpful for understanding the library. But changes are being made at each meeting, so the current working paper is the final word. HTH, --Beman

There appears to be a more recent PDF available, dated March 23, 2009. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf -Sid Sacek
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Beman Dawes Subject: Re: [boost] Interest in atomic library?
The best reference is the current C++ Standard Working Paper. Go to http://www.open-std.org/jtc1/sc22/wg21/ and select "Current C++ Standard Working Paper" in the "Other information" section. --Beman

Hi, I think every one wants a Atomic library in Boost following as much as possible the current standard. The interest is triple: first for the Boost developers using this library in its onw libraries, second for the users using these more permormant and thread-safe libraries, and for the developers using the library for its own applications. So, yes I'm interested in Boost.Atomic. There are already a lot of internal implementation in Boost. Maybe the authors can point to these implementations. It could be great if someone starts to make a concrete proposal. Best, Vicente ----- Original Message ----- From: "Sid Sacek" <ssacek@securewatch24.com> To: <boost@lists.boost.org> Sent: Thursday, April 23, 2009 4:36 PM Subject: Re: [boost] Interest in atomic library?
There appears to be a more recent PDF available, dated March 23, 2009. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf
-Sid Sacek
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Beman Dawes Subject: Re: [boost] Interest in atomic library?
The best reference is the current C++ Standard Working Paper. Go to http://www.open-std.org/jtc1/sc22/wg21/ and select "Current C++ Standard Working Paper" in the "Other information" section. --Beman
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Seth LaForge wrote:
In this day and age, running our C++ programs off fossil fuels makes a dangerous contribution to global warming and requires purchase of carbon offsets for ethical programming. Thus I think it's time for a Boost atomic power library. Oops, sorrry, wrong meaning of atomic.
What would people think of an atomic integer library, along the lines of Linux's asm/atomic.h? I'd propose a class atomic<T> implementing operations like atomic read (implicit conversion to T), atomic set (assignment from T), and compare-and-exchange. For integral types it would support atomic add and return result (operator+=), atomic subtract and return result (operator-=), atomic increment and return result (prefix operator++), and atomic decrement and return result (prefix operator--).
For arbitrary architectures or unhandled types of T, there would be a naive implementation using a mutex. On supported architectures there would be specializations for integral T types, using assembly to implement more efficient atomic operations. This assembly could pretty much just be borrowed from the Linux asm/atomic.h headers.
What do people think? I see pros: + Cross-platform efficient atomic operations for efficient threaded apps. I see cons: - Hard to predict whether your atomic ops will be efficient (no specialization for your architecture/T). - Some architectures may implement different atomic ops, making the above ops not the most efficient.
I think the pros outweight the cons. I'd personally much rather use a Boost.atomic library than asm/atomic.h.
Seth _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Intel's TBB has an atomic<T> http://www.threadingbuildingblocks.org/file.php?fid=77
participants (6)
-
Beman Dawes
-
jbosboom@uci.edu
-
Kenny Riddile
-
Seth LaForge
-
Sid Sacek
-
vicente.botet