Sent via Deja.com http://www.deja.com/
Before you buy.
In that they provide no intrinsic locking mechanisms (like critical
sections, semaphores etc), no. In that can they be used in a multi-threaded
environment where the programmer does take account of such an environment,
yes.
NeilB
__malloc_alloc_template<> on the typedef ..
typedef vector<int,__malloc_alloc_template<sizeof(int)> > v_int;
>Sorry for that question but I've never use STL before.
>Are queue, vector, list multithread safe?
In article <ezUJ$Bff$GA.207@cppssbbsa05>,
Depending upon your definition of thread safe, they either are or they are
not.
If you've got multiple threads doing reads and writes to a Queue, Vector,
List, String, (etc, etc) then the STL is absolutely NOT threadsafe. You need
to protect access (both for read and write) to the various STL members with
synchronization objects (of which Critical Sections seem to be the most
appropriate).
I *believe* that if you simply populate a List/String/Vector/Map/etc at init
time, you can then have several threads safely perform read operations
without any undue concern.
> you can make them safly if you user the
> __malloc_alloc_template<> on the typedef ..
>
> typedef vector<int,__malloc_alloc_template
> <sizeof(int)> > v_int;
I've never heard of that, and neither has the STL help files or the STL
books on my bookshelf.
You'll pardon my skepticism, but I just don't see any way this would help
with thread safety.
--
Chris Mullins
Chris Mullins wrote in message <891au4$2en$1...@ffx2nh3.news.uu.net>...
>well ..
>if you try to use sliconGraphics stl you will see on the doc that you can
>use 4 types of allcator's.
>if you will use the malloc_alloc it will be slow but thread safe.
>see www.sgi.com
As I read the SGI docs, even the default allocator "alloc" is
thread-safe in the sense that SGI is using it regarding allocators.
The web page http://www.sgi.com/Technology/STL/Allocators.html says
"alloc - The default allocator. It is thread-safe, and usually has
the best performance characteristics."
Thread safety of allocation is different from thread safety of access
to the container. Chris Mullen's reply is correct regarding access,
and this is probably what the original poster was referring to, since
he says "I've never use STL before".
Don