Is reading from std::vector thread safe?
me22
me22.ca@gmail.com
Thu Oct 2 17:54:00 GMT 2008
On Thu, Oct 2, 2008 at 13:47, Chris Hamons <chris.hamons@gmail.com> wrote:
> I've been told that in gcc 3.3, reading from std::string was not
> thread safe, and that in gcc 4.x it is now thread safe. Is this
> correct? Is it thread safe to iterate through a std::vector in gcc 3.3
> or gcc 4.x. I have not been able to find any documentation on what is
> and isn't threadsafe when it comes to stl and gcc.
>
In general, simultaneous reads of any std:: container are thread-safe.
However, as soon as you want to use any mutating function on a
container, all read and write accesses need to be mutexed. None of
them are lock-free.
For std::string, it's possible that it was ref-counted at some point,
which makes it harder to know which functions are mutating.
Not authoritative, but I hope it helps,
~ Scott
More information about the Gcc-help
mailing list