Re: Concurrent Containers
On 2010-09-01 17:58:03 -0400, Scott Meyers said:
On 9/1/2010 2:34 PM, Paavo Helde wrote:
Yes, sometimes such containers are exactly what is needed. However, given
that one can in about 20 lines create a template class which is able to
wrap any non-concurrent class and expose a locking proxy pointer for safe
concurrent access, this is not so difficult to achieve.
Can you elaborate on what you mean here? Suppose I want to take a
std::map or std::unordered_map (C++0x) and make it safe for multiple
threads to simultaneously perform insertions. What will a "locking
proxy pointer" do to enable this behavior?
I think this is the wrong level for design. It's gotten lost over the
years, but containers should typically implementation details, not
high-level design objects. If you need an object that can be used from
multiple threads to store objects and search for an object, its
interface might look like this:
template <class Ty>
class data_table
{
public:
void store(const Ty&);
const Ty& find(whatever);
private:
// none of your business! (but see below)
};
The implementation might well be a hash table, but the public interface
is far smaller than the interface for a hash table, and it's properly
synchronized for the operations that it provides.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)