Re: (No) Thread safty in VC 7.1 STL?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Arnaud Debaene (adebaene_at_club-internet.fr)
Date: 07/16/04


Date: Fri, 16 Jul 2004 14:55:42 +0200

Erik Nordahl wrote:
> Browsing in MSDN (for VS .NET 2003), I found the following:
>
> Quote START:
>
> When /MT, /MTd, /MD, or /MDd is used, the following thread-safety
> rules are in effect:
>
> Container Classes (vector, deque, list, queue, stack , priority_queue,
> valarray, map, multimap, set, multiset, basic_string, bitset) and
> complex
> For reads to the same object, the object is thread safe for reading:
>
> From one thread at a time when no writers on other threads.
> From many threads at a time when no writers on other threads.
> For writes to the same object, the object is thread safe for writing
> from one thread when no readers on other threads
>
> NOTE FOLLOWING LINE -->
> For reads to different objects of the same class, the object is thread
> safe for reading:
>
> From one thread at a time.
> From one thread at a time when no writers on other threads.
> From many threads at a time.
> From many threads at a time when no writers on other threads.
> For writes to different objects of the same class, the object is
> thread safe for writing:
>
> From one thread when no readers on other threads.
> From many threads.
>
> Quote END:
>
> My question: Can it be true that a write operation on ANY object of a
> certain type (e.g. vector) will endanger any read operation on ANY
> object of the same type (in any thread)?

No, if the 2 objects are different, you can write to them separately without
problem. There was a problem in VC6 because the STL implementation of some
containers used static varaibles, but this is no longer true in VC7 and
VC7.1.
>
> Because that will in effect make the STL implementation useless in
> multithread applications...
I agree that the MSDN documentation is not very explicit...

Arnaud
MVP - VC



Relevant Pages

  • Re: (No) Thread safty in VC 7.1 STL?
    ... > Quote START: ... > For reads to the same object, the object is thread safe for reading: ... > From many threads at a time when no writers on other threads. ... There was a problem in VC6 because the STL implementation of some ...
    (microsoft.public.vc.stl)
  • (No) Thread safty in VC 7.1 STL?
    ... Quote START: ... For reads to the same object, the object is thread safe for reading: ... >From many threads at a time when no writers on other threads. ... I specified the line in question above, and the full MSDN article ...
    (microsoft.public.vc.language)
  • (No) Thread safty in VC 7.1 STL?
    ... Quote START: ... For reads to the same object, the object is thread safe for reading: ... >From many threads at a time when no writers on other threads. ... I specified the line in question above, and the full MSDN article ...
    (microsoft.public.vc.stl)
  • Re: Thread safety in set
    ... bitset. ... From many threads at a time when no writers on other threads. ... For writes to the same object, the object is thread safe for writing from ... It has everything to do with multithreading. ...
    (microsoft.public.vc.stl)
  • Re: Thread safety in set
    ... priority_queue, valarray, map, multimap, set, multiset, basic_string, ... bitset. ... From many threads at a time when no writers on other threads. ... For writes to the same object, the object is thread safe for writing ...
    (microsoft.public.vc.stl)