473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Thread Safe, Standard Template Library, and C++

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

Sep 26 '07 #1
7 2855
Steven Woody 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?
C++ has no thread language support,
<url http://www.sgi.com/tech/stl/thread_safety.html/>

--
Thanks
Barry
Sep 26 '07 #2
On Sep 26, 8:55 pm, Barry <dhb2...@gmail.comwrote:
Steven Woody 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?

C++ has no thread language support,
<urlhttp://www.sgi.com/tech/stl/thread_safety.html/>
the link you given could not be found.

Sep 26 '07 #3
On 2007-09-26 14:54, Steven Woody 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?
They are (probably) thread safe as long as no two threads try to access
them at the same time. I say probably because 1) I have not studied all
the requirements of the containers in detail, but 2) while I cannot see
any reason why any of the would use static or global data I do not think
that the standard explicitly forbids it either.

--
Erik Wikström
Sep 26 '07 #4
On 2007-09-26 15:55, Steven Woody wrote:
On Sep 26, 8:55 pm, Barry <dhb2...@gmail.comwrote:
>Steven Woody 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?

C++ has no thread language support,
<urlhttp://www.sgi.com/tech/stl/thread_safety.html/>

the link you given could not be found.
www.sgi.com/tech/stl/thread_safety.html

--
Erik Wikström
Sep 26 '07 #5
On 9/26/2007 3:55 PM, Steven Woody wrote:
On Sep 26, 8:55 pm, Barry <dhb2...@gmail.comwrote:
>Steven Woody 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?
C++ has no thread language support,
<urlhttp://www.sgi.com/tech/stl/thread_safety.html/>

the link you given could not be found.
Drop the trailing '/' and it works.

S.
--
Stefan Naewe stefan dot naewe at atlas-elektronik dot com
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html
Sep 26 '07 #6
On Sep 26, 2:54 pm, Steven Woody <narkewo...@gmail.comwrote:
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?
The current version of the standard doesn't consider threads.
The next version will.

All of the implementations of the STL that I know of for the
"usual" machines (PC's under Windows or Linux, Sparc's under
Solaris, etc.) are thread safe, but do read the exact contract
each implements. (Modulo errors, of course. There is an error
in the g++ implementation of std::string, for example, although
it's really a very rare program which will encounter it. And
arguably, it's not an error because g++ doesn't claim to respect
the Posix guarantees, but only a much weaker set.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 27 '07 #7
On Sep 26, 4:39 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-09-26 14:54, Steven Woody wrote:
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?
They are (probably) thread safe as long as no two threads try
to access them at the same time. I say probably because 1) I
have not studied all the requirements of the containers in
detail, but 2) while I cannot see any reason why any of the
would use static or global data I do not think that the
standard explicitly forbids it either.
The allocators probably do access shared data. The g++
implementation of std::string also shares data between instances
in certain cases. Unless you have a guarantee, it's probably
best to assume that the objects aren't thread safe. (In fact,
unless you have a guarantee, you have to assume that they
aren't, because you don't know what "thread safe" means for
them.)

As far as I know, the standard containers (with the exception of
string) and algorithms in all of the libraries derive ultimately
from the implementation which is now at SGI, and provide the SGI
guarantee, at least when instantiated over the standard
allocator. (Obviously, if you provide the allocator, you have
to ensure its thread safety.) I think that all except g++
provide the SGI guarantee for all other elements of the standard
as well; some (e.g. Rogue Wave) provide considerably more, but
in practice, doing so slows up the components significantly,
while offering little or no advantage to the user. G++ formally
offers a much weaker guarantee, but in practice, the only
exception is in std::basic_string, and that only causes problems
in one very special case, which isn't very likely to occur in
practice.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: shishir | last post by:
Please validate the followings: STL is thread safe at class level. Iostream library is thread safe at object level. what does it mean and how is it useful for the programmers.
12
by: Brian Genisio | last post by:
Hi all, I am developing some software, that creates a tree of information. For each node, currently I am overriding the new operator, because it is a requirement that after initialization, no...
15
by: John Doe | last post by:
Hi all, I know the standard doesn't care about threads (wrongly :-) But in current compilers implementation, is the "list" which holds count of the occupied and free heap addresses SHARED among...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
7
by: Chad Zalkin | last post by:
We are evaluating some old code that was written as part of our math library. This code uses some optimizations that I'm not sure are necessary or safe, but is a source of debate between my...
22
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
2
by: ZHENG Zhong | last post by:
Hi, I implemented a small logging library with the API like this: logger& log = log_manager::instance().get_logger("my_logger"); log.stream(DEBUG) << "this is a debug message" << std::endl;...
44
by: climber.cui | last post by:
Hi all, Does anyone have experience on the thread-safty issue with malloc()? Some people said this function provided in stdlib.h is not thread- safe, but someone said it is thread safe. Is it...
3
by: =?Utf-8?B?anBhdHJjaWs=?= | last post by:
Don't see any official notice that compiled library dll's loaded in the BIN directory of an asp.net website need to be thread safe, but concurrent visits to the same web site sure bear this out....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.