Re: Thread safe hash_map in stl port linux
eladkatz@gmail.com wrote:
how can i make a hash_map class that contains an stl hash_map
object with thread safety,
I think that most implementations of the STL are thread safe. If
I'm not mistaken, STLport is based on the SGI implementation,
and that is thread safe, see:
http://www.sgi.com/tech/stl/thread_safety.html.
i.e. i want it to be locked by a mutex whenever it is used...
That's up to the user. Only the user knows when it is being
used. (Note that any iterator into the container may "use" it,
as may references returned by operator[].)
is there a design pattern or an example for doing this?
I'd call it more an anti-pattern: the idea that locking every
function somehow buys you anything. In the case where a
component can return a reference to internal data, it's totally
useless, by definition. (Even when that's not the case, the
locks almost always have a granularity that is too low.)
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]