Is there any easy way to get a thread safe edition of the shared_ptr
(BOOST_HAS_THREADS) and a "non" thread safe edition (BOOST_DISABLE_THREADS)
inside the same project?
The thread safe edition of the shared_ptr is a bit slower and I would like
to able to use the non thread safe shared_ptr, when I known it only be used
on the same thread.
As a solution I thought I could do something like this, so I would not have
to edit/copy any boost .hpp file :
//
// MyApp.cpp
//
#define BOOST_HAS_THREADS
#include "boost/smart_ptr.hpp"
namespace boost_nothread
{
#define BOOST_DISABLE_THREADS
#include "boost/smart_ptr.hpp"
}
void f()
{
boost::shared_ptr <int> spIntTS; // thread safe smart pointer
boost_nothread::shared_ptr <int> spInt; // non thread safe smart
pointer
}
////////
The above sample does not work - what should I do instead?
Regards,
René
Try to convince Dimov that policy-based designs/interfaces aren't that bad;
and that, in general, the stuff managed by smart pointers isn't necessarily
process-wide/thread-shared stuff "by default"... like global heap, current
working directory, etc.
regards,
alexander.
--
"Yes, every user of shared_ptr that has BOOST_HAS_THREADS defined is burdened
with the overhead of having a shared_ptr that works. :-) shared_ptr follows
the standard library practice here; every user is burdened with a
synchronized heap allocator, too."
>Hi.
>
>Is there any easy way to get a thread safe edition of the shared_ptr
>(BOOST_HAS_THREADS) and a "non" thread safe edition (BOOST_DISABLE_THREADS)
>inside the same project?
>
>The thread safe edition of the shared_ptr is a bit slower and I would like
>to able to use the non thread safe shared_ptr, when I known it only be used
>on the same thread.
>
>As a solution I thought I could do something like this, so I would not have
>to edit/copy any boost .hpp file :
>
>//
>// MyApp.cpp
>//
>
>#define BOOST_HAS_THREADS
>#include "boost/smart_ptr.hpp"
>
>namespace boost_nothread
>{
> #define BOOST_DISABLE_THREADS
> #include "boost/smart_ptr.hpp"
using namespace boost;
>}
>
>void f()
>{
> boost::shared_ptr <int> spIntTS; // thread safe smart pointer
>
> boost_nothread::shared_ptr <int> spInt; // non thread safe smart
>pointer
>}
>
>////////
>
>The above sample does not work - what should I do instead?
With the change above it compiled at least...
Tom