n2427 atomic implementation?

Hi, Can the N2427 - C++ Atomic Types and Operations be implemented without the help of the compiler? Do some one have a partial implementation? Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
Can the N2427 - C++ Atomic Types and Operations be implemented without the help of the compiler?
No. They don't need to be intrinsics --- if you can write inline assembler (or separately-compiled assembler for that matter) then you can write the operations themselves directly. You might even be able to use simple C++ (e.g. just plain assignment for load or store). The reason you need compiler support is preventing inappropriate optimizations: atomic operations can't be optimized out, and generally must not be reordered before or after any other operations. This means that even non-atomic stores performed before an atomic store have to be complete, and can't be cached in a register (for example). Also, loads that occur after an atomic operation cannot be hoisted before the atomic op. On some compilers, just using inline assembler is enough. On others, calling an external function is enough. MSVC provides _ReadWriteBarrier() to provide the compiler ordering. Other compilers need other flags.
Do some one have a partial implementation?
I have a full implementation for MSVC 2008 as part of my C++0x thread library, currently in beta: http://www.stdthread.co.uk Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Wednesday, November 19, 2008 12:14 AM Subject: Re: [boost] n2427 atomic implementation?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
Can the N2427 - C++ Atomic Types and Operations be implemented without the help of the compiler?
No.
They don't need to be intrinsics --- if you can write inline assembler (or separately-compiled assembler for that matter) then you can write the operations themselves directly. You might even be able to use simple C++ (e.g. just plain assignment for load or store).
The reason you need compiler support is preventing inappropriate optimizations: atomic operations can't be optimized out, and generally must not be reordered before or after any other operations. This means that even non-atomic stores performed before an atomic store have to be complete, and can't be cached in a register (for example). Also, loads that occur after an atomic operation cannot be hoisted before the atomic op.
On some compilers, just using inline assembler is enough. On others, calling an external function is enough. MSVC provides _ReadWriteBarrier() to provide the compiler ordering. Other compilers need other flags.
Do some one have a partial implementation?
I have a full implementation for MSVC 2008 as part of my C++0x thread library, currently in beta: http://www.stdthread.co.uk
Hi, Sorry but I don't have MSVC 2008, to do the installation. So I have just take a look at the doc and header files. BTW, I was not aware that your future proposal was currently adopted by the C++ Standard. Is it? " just::thread Headers The just::thread library provides the following Standard C++0x headers: <chrono> <condition_variable> <cstdatomic> <future> <mutex> <ratio> <stdatomic.h> <system_error> <thread> " How your 'just::' implementation performs respect to Boost.Thread, Boost.Chrono and Boost.Exception? Thanks,

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
BTW, I was not aware that your future proposal was currently adopted by the C++ Standard. Is it?
Yes. It was approved at the October 2008 meeting. See http://www.justsoftwaresolutions.co.uk/cplusplus/cplusplus-standards-committ...
How your 'just::' implementation performs respect to Boost.Thread, Boost.Chrono and Boost.Exception?
It is similar in many ways to Boost.Thread, but the condition variable algorithm has been improved, and the deadlock detection is entirely new. I've only glanced at Beman's Boost.Chrono stuff, but it seems similar. For exception_ptr, my code uses an improved version of the MSVC-specific code I submitted (but which is not yet included in Boost.Exception) which allows any exception to be cloned, without prior registration. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Wednesday, November 19, 2008 5:47 PM Subject: Re: [boost] n2427 atomic implementation?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
BTW, I was not aware that your future proposal was currently adopted by the C++ Standard. Is it?
Yes. It was approved at the October 2008 meeting. See http://www.justsoftwaresolutions.co.uk/cplusplus/cplusplus-standards-committ...
Congratulations, When the review of the Boost.Futures library will take place? Vicente

Anthony Williams wrote:
For exception_ptr, my code uses an improved version of the MSVC-specific code I submitted (but which is not yet included in Boost.Exception) which allows any exception to be cloned, without prior registration.
Does it work with 64-bit MSVC? I've adapted your code to get error information out of any exception, but I don't know how to adapt the code to 64-bit compilation. Sebastian

Sebastian Redl <sebastian.redl@getdesigned.at> writes:
Anthony Williams wrote:
For exception_ptr, my code uses an improved version of the MSVC-specific code I submitted (but which is not yet included in Boost.Exception) which allows any exception to be cloned, without prior registration.
Does it work with 64-bit MSVC? I've adapted your code to get error information out of any exception, but I don't know how to adapt the code to 64-bit compilation.
I haven't yet looked at the issues with 64-bit MSVC. I'm fairly sure it uses a different exception model, so it won't work without some level of tweaking. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Hi, Did you look at STLSoft? Thanks Regards, Ahsan ----- Original Message ----- From: "vicente.botet" <vicente.botet@wanadoo.fr> Newsgroups: gmane.comp.lib.boost.devel To: <boost@lists.boost.org> Sent: Wednesday, November 19, 2008 3:43 AM Subject: n2427 atomic implementation?
Hi,
Can the N2427 - C++ Atomic Types and Operations be implemented without the help of the compiler? Do some one have a partial implementation?
Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

----- Original Message ----- From: "Ahsan Baig" <ahsantuple@gmail.com> To: <boost@lists.boost.org> Sent: Friday, November 21, 2008 8:54 AM Subject: Re: [boost] n2427 atomic implementation?
Hi,
Did you look at STLSoft?
No, I didn't. I was looking for open source. Thanks anyway, Vicente

vicente.botet wrote:
Hi,
Can the N2427 - C++ Atomic Types and Operations be implemented without the help of the compiler? Do some one have a partial implementation?
Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Inside boost/detail/ there are implementations for atomic int counters, with implementations for Win32, GCC and using pthread mutexes when no platform-optimized solution exists. AFAIK, there is no complete n2427 implementation. The atomic_ops library is more complete but only provides a platform independent interface for atomic operations, which is C-based. Moreover, there is no implementation for XL C compiler on AIX. The just::thread implementation from http://www.stdthread.co.uk/ is only for Win32. Is anyone else interested in implementing the proposal in n2427?
participants (5)
-
Ahsan Baig
-
Anthony Williams
-
Ioannis Papadopoulos
-
Sebastian Redl
-
vicente.botet