On 10/5/06, Joaquín Mª López Muñoz <joaquin@tid.es> wrote:
No, it is not safe to insert from two threads into the same container. The
thread safety guarantees aplying to Boost.MultiIndex (and to most STL
implementations as well) are:

1. Concurrent access to different containers is safe.
2. Concurrent read-only access to the same container is safe

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


I know the standard says nothing about thread-safety (and I also know they are thinking about saying a few things next time), but I was just wondering what everyone thinks about #2 above - concurrent reads to the same container.  I've assumed that in the past as well,  but how safe do people think that is?  If they add threading to the next standard, will they likely add #2 as a requirement on the standard containers?  What I'm thinking about, for example, is a map-like container based on, say, splay trees, where the last accessed item gets moved towards the top of the tree, which is a nice property for caches. But this would mean mutable data that changes during reads.  So I would have to protect that with a mutex or something?

Thanks,
Tony