Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multithread

0 views
Skip to first unread message

and...@mail.serve.com

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to
Sorry for that question but I've never use STL before.
Are queue, vector, list multithread safe?
Thank you
Andrey


Sent via Deja.com http://www.deja.com/
Before you buy.

NeilB

unread,
Feb 22, 2000, 3:00:00 AM2/22/00
to
<and...@mail.serve.com> wrote in message news:88uqne$fhl$1...@nnrp1.deja.com...

> Sorry for that question but I've never use STL before.
> Are queue, vector, list multithread safe?

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

rafi

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
yes they are ..
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;


>Sorry for that question but I've never use STL before.
>Are queue, vector, list multithread safe?

and...@mail.serve.com

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
I'm sorry but what is __malloc_alloc_template? I cannot compile
because there is no definition for __malloc_alloc_template. What header
has it? and there is nothing in a help.
Andrey

In article <ezUJ$Bff$GA.207@cppssbbsa05>,

Chris Mullins

unread,
Feb 23, 2000, 3:00:00 AM2/23/00
to
rafi Wrote:
>
> >Sorry for that question but I've never use STL before.
> >Are queue, vector, list multithread safe?
>
> yes they are ..

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

rafi

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
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


Chris Mullins wrote in message <891au4$2en$1...@ffx2nh3.news.uu.net>...

Don McClimans

unread,
Feb 25, 2000, 3:00:00 AM2/25/00
to
On Thu, 24 Feb 2000 16:58:08 +0200, "rafi" <ra...@ffff.com> wrote:

>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


0 new messages