Topic: Thread Safe, Standard Template Library, and C++


Author: Steven Woody <narkewoody@gmail.com>
Date: Wed, 26 Sep 2007 11:41:27 CST
Raw View
hi,

are those containers provided in std thread safe? if not, does the std
( or the language itself ) provide any method to protect critical
section in a thread unsafe operation?

thanks.

-
woody

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: int19h@gmail.com
Date: Wed, 26 Sep 2007 12:36:16 CST
Raw View
On Sep 26, 9:41 pm, Steven Woody <narkewo...@gmail.com> wrote:
> hi,
>
> are those containers provided in std thread safe? if not, does the std
> ( or the language itself ) provide any method to protect critical
> section in a thread unsafe operation?

There's no such guarantee in the C++03 standard (it does not discuss
threads or threading issues at all), and most (all?) existing
implementations are not thread-safe. There are active proposals to
rectify both problems, "Thread-Safety in the Standard Library" (N2410,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2410.html)
and "Multi-threading Library for Standard C++" (N2320,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html),
which are considered for inclusion into C++09.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: jdennett@acm.org (James Dennett)
Date: Wed, 26 Sep 2007 19:36:57 GMT
Raw View
int19h@gmail.com wrote:
> On Sep 26, 9:41 pm, Steven Woody <narkewo...@gmail.com> wrote:
>> hi,
>>
>> are those containers provided in std thread safe? if not, does the std
>> ( or the language itself ) provide any method to protect critical
>> section in a thread unsafe operation?
>
> There's no such guarantee in the C++03 standard (it does not discuss
> threads or threading issues at all), and most (all?) existing
> implementations are not thread-safe.

Actually most, or maybe all, existing STL implementations are
thread-safe in a sense described on SGI's website, among others.

> There are active proposals to
> rectify both problems, "Thread-Safety in the Standard Library" (N2410,
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2410.html)
> and "Multi-threading Library for Standard C++" (N2320,
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html),
> which are considered for inclusion into C++09.

It's likely that the new standard's guarantees for thread safety
of containers will reflect existing practice, with wording rather
tightened up from the SGI version.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Steven Woody <narkewoody@gmail.com>
Date: Fri, 28 Sep 2007 11:12:30 CST
Raw View
On Sep 27, 3:36 am, jdenn...@acm.org (James Dennett) wrote:
> int...@gmail.com wrote:
> > On Sep 26, 9:41 pm, Steven Woody <narkewo...@gmail.com> wrote:
> >> hi,
>
> >> are those containers provided in std thread safe? if not, does the std
> >> ( or the language itself ) provide any method to protect critical
> >> section in a thread unsafe operation?
>
> > There's no such guarantee in the C++03 standard (it does not discuss
> > threads or threading issues at all), and most (all?) existing
> > implementations are not thread-safe.
>
> Actually most, or maybe all, existing STL implementations are
> thread-safe in a sense described on SGI's website, among others.
>
> > There are active proposals to
> > rectify both problems, "Thread-Safety in the Standard Library" (N2410,
> >http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2410.html)
> > and "Multi-threading Library for Standard C++" (N2320,
> >http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html),
> > which are considered for inclusion into C++09.
>
> It's likely that the new standard's guarantees for thread safety
> of containers will reflect existing practice, with wording rather
> tightened up from the SGI version.
>
> -- James
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

in particulary, are you get any information on Microsoft's
implementation of STL, is it thread-safe? thanks.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: int19h@gmail.com
Date: Sat, 29 Sep 2007 11:08:12 CST
Raw View
On 28 Sep, 21:12, Steven Woody <narkewo...@gmail.com> wrote:
> in particulary, are you get any information on Microsoft's
> implementation of STL, is it thread-safe? thanks.

http://msdn2.microsoft.com/en-us/library/c9ceah3b(VS.80).aspx

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "terminator(jam)" <farid.mehrabi@gmail.com>
Date: Tue, 2 Oct 2007 12:00:31 CST
Raw View
On Sep 28, 8:12 pm, Steven Woody <narkewo...@gmail.com> wrote:
> On Sep 27, 3:36 am, jdenn...@acm.org (James Dennett) wrote:
>
>
>
>
>
> > int...@gmail.com wrote:
> > > On Sep 26, 9:41 pm, Steven Woody <narkewo...@gmail.com> wrote:
> > >> hi,
>
> > >> are those containers provided in std thread safe? if not, does the std
> > >> ( or the language itself ) provide any method to protect critical
> > >> section in a thread unsafe operation?
>
> > > There's no such guarantee in the C++03 standard (it does not discuss
> > > threads or threading issues at all), and most (all?) existing
> > > implementations are not thread-safe.
>
> > Actually most, or maybe all, existing STL implementations are
> > thread-safe in a sense described on SGI's website, among others.
>
> > > There are active proposals to
> > > rectify both problems, "Thread-Safety in the Standard Library" (N2410,
> > >http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2410.html)
> > > and "Multi-threading Library for Standard C++" (N2320,
> > >http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html),
> > > which are considered for inclusion into C++09.
>
> > It's likely that the new standard's guarantees for thread safety
> > of containers will reflect existing practice, with wording rather
> > tightened up from the SGI version.
>
> > -- James
>
> > ---
> > [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> > [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> > [              --- Please see the FAQ before posting. ---               ]
> > [ FAQ:http://www.comeaucomputing.com/csc/faq.html                    ]
>
> in particulary, are you get any information on Microsoft's
> implementation of STL, is it thread-safe? thanks.
>

you can dig into the library , open the header files and see if you
can find any thread issues in the STL.I think there has been no
consideration of threads in many existing implementations of STL.

regards,
FM.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: James Dennett <jdennett@acm.org>
Date: Wed, 3 Oct 2007 12:07:23 CST
Raw View
terminator(jam) wrote:
>
> you can dig into the library , open the header files and see if you
> can find any thread issues in the STL.I think there has been no
> consideration of threads in many existing implementations of STL.

Given the mandated interfaces of the STL, combined with common
platform-specific thread-safety guarantees for underlying components
such as memory allocators, in most cases it's not necessary for
implementors to do anything special to get thread safety (in the
sense documented on SGI's website long ago) for STL components.

There's no real need for shared state, hence no significant
multi-threading issues.

If we extend the discussion to the whole Standard Library, there
are much more interesting issues, which are still being addressed.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]