
The docs state the pointers are "as close to raw pointers as possible" and that makes sense, heh. On Mon, Apr 21, 2008 at 2:20 PM, Tim Blechmann <tim@klingt.org> wrote:
On Mon, 21 Apr 2008 09:37:23 -0700, Patrick Twohig wrote:
I thought boost::shared_ptr was lock-free and thread safe on the major platforms supported by boost. I could be wrong though.
there are the following issues with boost::shared_ptr:
thread 1 accesses object, thread 2 frees it object ... one would need a thread-local copy of the shared_ptr to dereference it or use hazard pointers/pass-the-buck -- shared_ptr<foo_t> foo (new foo_t());
void thread_1(void) { foo->bar(); }
void thread_2(void) { foo.reset(); } --
copying problem if thread 1 updates the pointer entry of foo, then thread 2 updates both pointer and reference count entry, then thread 1 updates the reference count foo would point to the object managed by bar, using the reference count of baz ... one would need a way to validate both object and reference count, lance suggested a tag, which would add another indirection, or an atomic double- word read instruction -- shared_ptr<foo_t> foo (new foo_t()); shared_ptr<foo_t> bar (new foo_t()); shared_ptr<foo_t> baz (new foo_t());
void thread_1(void) { foo = bar; }
void thread_2(void) { foo = baz; } --
cheers, tim
-- tim@klingt.org http://tim.klingt.org
You can play a shoestring if you're sincere John Coltrane
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost