g wrote:
>
> Wouldn't be better shared_ptr constructor to have an argument
> <true/false> for thread-safe reference counting?? The default should be
> true and in case you dont want thread-safe RC create a shared_ptr with
> false in constructor. The reason for this is to avoid the cost of the
> memmory barriers where you don't need them.
>
> At the moment if your application is multithreaded boost will choose to
> use thread-safe RC but in many cases( local containers with
> shared_ptrs) thread-safe RC doesn't have any sense.....becouse the
> objects are owned by only one thread.
>
I think you're right that you shouldn't have to pay for sychronization
when you don't need it, I think a better approach is to have two
different types of shared pointer instead of one that may or may not be
synchronized. On the other hand, cases where you truly need to share
heap-allocated objects between threads are probably sufficiently rare
that maybe there's no need for synchronization at all. James Kanze, on
comp.std.c++, has suggested that auto_ptr is sufficient for sharing
objects between threads: create it in one thread and pass it to another.
--
-- Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (
www.petebecker.com/tr1book)