Re: vector
Cholo Lennon <chololennon@hotmail.com> wrote:
Vectors are thread safe for reading,
Are you sure?
See some vector member functions (VC 7.1):
---------------------------------------
reference at(size_type _Off)
{
if (size() <= _Off)
_Xran();
return (*(begin() + _Off));
}
reference operator[](size_type _Off)
{
return (*(begin() + _Off));
}
---------------------------------------
You can easily invalidate them from another thread
That's why Bo says, "If one of the threads modifies the vector, all the
threads will have to use some locking mechanism." "All" here means
all, both readers and writers. Vector (and all other STL classes)
supports multiple simultaneous reading threads, but as soon as one
thread is writing, it requires exclusive access.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925