On Thu, Sep 3, 2009 at 2:30 AM, Stefan Strasser
mutex.lock() weak_ptr<MyClass> local_weak_ptr (globally_ptr) ; mutex.lock()
why would you even need a lock here?
Because it's unsafe otherwise.
the shared_ptr doc says that you can expect the same thread safety from shared_ptr as you can from built-in types.
This is true, but you're drawing the wrong conclusion from it. You need a lock around built-in types as well. You need to use an "atomic" type to safely do what you're saying. In the same documentation, they give examples which are enlightening: //--- Example 3 --- // thread A p = p3; // reads p3, writes p // thread B p3.reset(); // writes p3; undefined, simultaneous read/write
you can use multiple-readers-single-writer without any locks on built-in types.
Not true. You can use multiple-readers, NO-writers without any locks, however. Chris