Re: why boost:shared_ptr so slower?
"Juha Nieminen" <nospam@thanks.invalid> wrote in message
news:%Djjm.223$1Y6.48@read4.inet.fi...
Keith H Duggar wrote:
Boost shared_ptr is not "thread safe" by any standard that is
usually meant by the term:
http://www.boost.org/doc/libs/1_39_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety
First you claim that it's not thread-safe, and then you point to the
documentation which says that it is.
ie "the same level of thread safety as built-in types" means
not "thread safe".
You are confusing two different types of thread-safety.
[...]
FWIW, Boost shared_ptr only provides basic/normal thread-safety. It does NOT
provide strong thread-safety in any way shape or form. Read the entire
following thread:
http://groups.google.com/group/comp.programming.threads/browse_frm/thread/e5167941d32340c6/1b2e1c98fa9ad7c7
You simply cannot use shared_ptr in a scenario which demands strong thread
safety level. For example, this will NOT work:
_______________________________________________________________
static shared_ptr<foo> global_foo;
void writer_threads() {
for (;;) {
shared_ptr<foo> local_foo(new foo);
global_foo = local_foo;
}
}
void reader_threads() {
for (;;) {
shared_ptr<foo> local_foo(global_foo);
local_foo->read_only_operation()();
}
}
_______________________________________________________________
If you want to use shared_ptr this way, you need a mutex:
_______________________________________________________________
static shared_ptr<foo> global_foo;
void writer_threads() {
for (;;) {
shared_ptr<foo> local_foo(new foo);
// lock
global_foo = local_foo;
// unlock
}
}
void reader_threads() {
for (;;) {
// lock
shared_ptr<foo> local_foo(global_foo);
// unlock
local_foo->read_only_operation()();
}
}
_______________________________________________________________