http://www.boost.org/doc/libs/1_46_0/libs/smart_ptr/shared_ptr.htm#ThreadSafety

This section somewhat confused me, in my code I have a matrix of shared_ptr's pointing to an entirely thread-safe class.

But the shared_ptr documentation says it is only as thread-safe as the built-in C++ types. Does this mean that if I read/write to my thread-safe class using shared_ptr's at the same time it won't work?

To help illustrate, say I have a shared_ptr pointing to an instance of my thread-safe class, and a function which returns a new shared_ptr pointing to the same instance of my class.

Can I use the new shared_ptr to access my class without worry, (assuming the instance won't be destroyed)?

>>Can I use the new shared_ptr to access my class without worry, (assuming the instance won't be destroyed)?
Yes. The "thread-safety" of shared_ptr has to do with modifying the pointer value stored in the shared_ptr. In that regard, the share_ptr has exactly the same thread-safety as a raw-pointer (which is basically none). When it comes to dereferencing the pointer (accessing the object it points), that becomes the domain of the thread-safety of that class (i.e. if your class is thread-safe, accessing a shared object through a shared_ptr will be thread-safe). The thread-safety concerns with shared_ptr only have to do with threads that share the same pointer (not copies of the pointer). But, dereferencing a pointer is always thread-safe by itself (it is a read-only (const) operation) as long as another thread is not changing that pointer's value at the same time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.