$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Tim Blechmann (tim_at_[hidden])
Date: 2008-04-21 17:20:24
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_at_[hidden]
http://tim.klingt.org
You can play a shoestring if you're sincere
John Coltrane