multi-threading with maps/vectors 
Author Message
 multi-threading with maps/vectors

I've read many postings on stl containers and multi-threading, but I have
yet to find a concrete answer to a question I have.  Assume we populate a
map with objects that themselves contain a vector. Once the population
process is complete, no more writes are done.  Will concurrent reads to the
map and the contained vectors be thread safe? More importantly, if I return
a pointer to an object in one of the vectors, is it possible for another
thread to invalidate that pointer?

Thanks,
Eric



Fri, 10 Oct 2003 15:52:09 GMT  
 multi-threading with maps/vectors

Quote:
> I've read many postings on stl containers and multi-threading, but I have
> yet to find a concrete answer to a question I have.  Assume we populate a
> map with objects that themselves contain a vector. Once the population
> process is complete, no more writes are done.  Will concurrent reads to
the
> map and the contained vectors be thread safe?

Effectively, yes, though the STL makes no guarantees in this area.

Quote:
> More importantly, if I return
> a pointer to an object in one of the vectors, is it possible for another
> thread to invalidate that pointer?

Of course it can - it could delete it without writing to the vector.

NeilB



Fri, 10 Oct 2003 19:41:34 GMT  
 multi-threading with maps/vectors

Quote:

> I've read many postings on stl containers and multi-threading, but I have
> yet to find a concrete answer to a question I have.  Assume we populate a
> map with objects that themselves contain a vector. Once the population
> process is complete, no more writes are done.  Will concurrent reads to the
> map and the contained vectors be thread safe?

Yes.

Quote:
>                                              More importantly, if I return
> a pointer to an object in one of the vectors, is it possible for another
> thread to invalidate that pointer?

No.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Fri, 10 Oct 2003 20:41:15 GMT  
 multi-threading with maps/vectors



Quote:

> > I've read many postings on stl containers and multi-threading, but I
have
> > yet to find a concrete answer to a question I have.  Assume we populate
a
> > map with objects that themselves contain a vector. Once the population
> > process is complete, no more writes are done.  Will concurrent reads to
the
> > map and the contained vectors be thread safe?

> Yes.

> >                                              More importantly, if I
return
> > a pointer to an object in one of the vectors, is it possible for another
> > thread to invalidate that pointer?

> No.

Eh? Consider

// thread A

Thing * p1 = vec[0];

// thread B

Thing * p2 = vec[0];
delete p2;

I would say p1 is now invalid.

NeilB



Fri, 10 Oct 2003 19:52:36 GMT  
 multi-threading with maps/vectors

Quote:





> > > I've read many postings on stl containers and multi-threading, but I
> have
> > > yet to find a concrete answer to a question I have.  Assume we
populate
> a
> > > map with objects that themselves contain a vector. Once the population
> > > process is complete, no more writes are done.  Will concurrent reads
to
> the
> > > map and the contained vectors be thread safe?

> > Yes.

> > >                                              More importantly, if I
> return
> > > a pointer to an object in one of the vectors, is it possible for
another
> > > thread to invalidate that pointer?

> > No.

> Eh? Consider

> // thread A

> Thing * p1 = vec[0];

> // thread B

> Thing * p2 = vec[0];
> delete p2;

> I would say p1 is now invalid.

My interpretation of the original post was that the questions referred to
read safety.  Clearly the poster understands that if any thread makes
changes to the data structure then thread-safety will be compromised.
And deleting the data is a fairly major change!


Fri, 10 Oct 2003 21:02:49 GMT  
 multi-threading with maps/vectors
Isn't this the place where you're supposed to point out that there's a bug
the MSVC version that can cause threads accessing maps to deadlock, and that
they should buy Dinkumware's update version ;-?

I'm not trying to be cheeky - we bought it here....

JD


Quote:

> > I've read many postings on stl containers and multi-threading, but I
have
> > yet to find a concrete answer to a question I have.  Assume we populate
a
> > map with objects that themselves contain a vector. Once the population
> > process is complete, no more writes are done.  Will concurrent reads to
the
> > map and the contained vectors be thread safe?

> Yes.

> >                                              More importantly, if I
return
> > a pointer to an object in one of the vectors, is it possible for another
> > thread to invalidate that pointer?

> No.

> P.J. Plauger
> Dinkumware, Ltd.
> http://www.dinkumware.com



Sat, 11 Oct 2003 02:32:53 GMT  
 multi-threading with maps/vectors

Quote:
>Isn't this the place where you're supposed to point out that there's a bug
> the MSVC version that can cause threads accessing maps to deadlock,

What bug is this? Was this fixed in Service Pack5 of Visual Studio.

Thanks!

-Ajay



Quote:
> Isn't this the place where you're supposed to point out that there's a bug
> the MSVC version that can cause threads accessing maps to deadlock, and
that
> they should buy Dinkumware's update version ;-?

> I'm not trying to be cheeky - we bought it here....

> JD




> > > I've read many postings on stl containers and multi-threading, but I
> have
> > > yet to find a concrete answer to a question I have.  Assume we
populate
> a
> > > map with objects that themselves contain a vector. Once the population
> > > process is complete, no more writes are done.  Will concurrent reads
to
> the
> > > map and the contained vectors be thread safe?

> > Yes.

> > >                                              More importantly, if I
> return
> > > a pointer to an object in one of the vectors, is it possible for
another
> > > thread to invalidate that pointer?

> > No.

> > P.J. Plauger
> > Dinkumware, Ltd.
> > http://www.dinkumware.com



Sat, 11 Oct 2003 07:38:51 GMT  
 multi-threading with maps/vectors

Quote:
> Isn't this the place where you're supposed to point out that there's a bug
> the MSVC version that can cause threads accessing maps to deadlock, and that
> they should buy Dinkumware's update version ;-?

> I'm not trying to be cheeky - we bought it here....

Well, yes, but I still believe that the primary purpose of newsgroups is
to exchange technical information. We do our best to sell only subliminally...

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com



Sat, 11 Oct 2003 08:28:33 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Embedded (Multi)Maps Within Vector (newbie question)

2. Multi-threading and threadstate handle maps

3. Accessing map elements in vector of maps

4. Multi-Threading, Multi-Functions, Real-Time, How?

5. Multi-thread, thread pool, or asynchronous socket

6. Help: Multi-thread, thread pool, or asynchronous socket

7. Single Thread VS. Multi Thread

8. Threaded -vs- Multi-threaded Question

9. libraries built single threaded in a multi-threaded project

10. Threads and Multi threads

11. MFC UI Thread doesnt start when COM method called in multi-threaded MFC dialog App

12. Multithreading, User Interface Threads, SetWindowText/SendMessage, Thread Hangs

 

 
Powered by phpBB® Forum Software