
Hi, I am looking for an efficient way to use boost::intrusive_ptr in a multi-threaded application. In the source-tree I encountered the macro BOOST_INTERLOCKED_INCREMENT/DECREMENT. Should I use these too and how are these implemented in Linux? Where can I find documentation on these macros? Thank you, Andrej

Andrej van der Zee wrote:
I am looking for an efficient way to use boost::intrusive_ptr in a multi-threaded application. In the source-tree I encountered the macro BOOST_INTERLOCKED_INCREMENT/DECREMENT. Should I use these too and how are these implemented in Linux?
No, you shouldn't use these macros. They are Windows-specific and correspond to InterlockedIncrement/InterlockedDecrement but don't require the inclusion of windows.h. If you are targeting the new C++0x, use std::atomic; otherwise, until Boost.Atomic is available, you may try boost::detail::atomic_count. It's, however, undocumented.

Hi, Thanks for your reply.
No, you shouldn't use these macros. They are Windows-specific and correspond to InterlockedIncrement/InterlockedDecrement but don't require the inclusion of windows.h. If you are targeting the new C++0x, use std::atomic; otherwise, until Boost.Atomic is available, you may try boost::detail::atomic_count. It's, however, undocumented.
I am using boost::detail::atomic_count now. I saw it is implemented using a scoped_lock for pthreads. Is there any advantage of using C++0x in terms of performance on Linux? Cheers, Andrej

Andrej van der Zee wrote:
I am using boost::detail::atomic_count now. I saw it is implemented using a scoped_lock for pthreads.
This depends on your gcc version (if you're using gcc) and your target platform.
Is there any advantage of using C++0x in terms of performance on Linux?
There should be as std::atomic should use atomic operations, but again, it depends on the gcc version and the target platform :-)

Hi,
There should be as std::atomic should use atomic operations, but again, it depends on the gcc version and the target platform :-)
I am using gcc 4.5.2 on Ubuntu amd64. But C++0x still seems too experimental for my purpose anyway: http://gcc.gnu.org/projects/cxx0x.html Thanks for your help, Andrej
participants (2)
-
Andrej van der Zee
-
Peter Dimov