Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

boost shared_ptr - thread safe and non thread safe editions

9 views
Skip to first unread message

René Dalby Carlsen

unread,
Jul 23, 2002, 1:13:04 AM7/23/02
to
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"
}

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é


Alexander Terekhov

unread,
Jul 23, 2002, 4:48:15 AM7/23/02
to

"René Dalby Carlsen" wrote:
[...]

> The above sample does not work - what should I do instead?

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."

-- http://aspn.activestate.com/ASPN/Mail/Message/1263557

tom_usenet

unread,
Jul 23, 2002, 8:12:52 AM7/23/02
to
On Tue, 23 Jul 2002 07:13:04 +0200, "René Dalby Carlsen"
<re...@carlsens.net> wrote:

>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

0 new messages