Do I need to protect read access to an STL container in a multithreading environment?

Yes, the read threads will need some sort of mutex control, otherwise the write will change things from under it.

A reader/writer mutex should be enough. But strictly speaking this is an implmentation-specific issue. It’s possible that an implementation may have mutable members even in const objects that are read-only in your code.

Leave a Comment