Re: [boost] Proposal to add smart_ptr to the boost library

"Sam Partington" <sam.partington@gmail.com> wrote in message news:<546fdb840601300802v13f0e09cg3618caf96a4ea960@mail.gmail.com>...
You can avoid having to make the implementation thread safe by making the pointee thread safe. This can be done by using an intrusive lock.
How? The FAQ is talking about making the reference count thread safe,
not the object thread safe.
class A { };
void f(ptr<A> a) { }
int main() { ptr<A> a(new A); boost::thread t(boost::bind(f, a)); }
Which thread does the deallocation of a? What protects both of them from trying to deallocate it at the same time?
I guess this could be considered not enough of an advantage if 22% to 30% extra efficiency is not that important. But some developers would differ.
Until there is a thread safe implemenation then any performance comparisons are irrelevant because you're comparing apples and oranges.
Thanks for the clarification Sam, but I know what the FAQ is talking about. I stand by my statement. The smart pointer can be made thread safe by using an intrusive lock. The idea behind this, is if you lock the pointee, before trying to access the smart pointer's data members, than you have a thread safe smart pointer. With the smart pointer I'm proposing, you can have a 10 reference link smart pointers, and if one of them has the pointee locked, than the others will not be able to access their data members until the pointee is unlocked.
participants (1)
-
David Maisonave