Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #294

Re: STL containers are not thread-safe!

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!news.albasani.net!.POSTED!not-for-mail
From Dave Abrahams<dave@boostpro.com>
Newsgroups comp.std.c++
Subject Re: STL containers are not thread-safe!
Date Wed, 14 Sep 2011 11:15:51 -0700 (PDT)
Organization unknown
Lines 31
Sender std-cpp-request@vandevoorde.com
Approved stephen.clamage@oracle.com
Message-ID <m2d3f4e1nc.fsf@pluto.luannocracy.com> (permalink)
References <7b4b5352-05a4-436e-8c57-aa51d4116428@glegroupsg2000goo.googlegroups.com>
Content-Type text/plain
X-Trace news.albasani.net erc6eUs3dY/5k8mZ6wZJonoHPNxhGw5X7arot3b70ACSbFNwQfAsBTQ9BQT2ISf4joUnT7W6ZFWBadgUvr0mhA==
NNTP-Posting-Date Wed, 14 Sep 2011 18:15:53 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="CZ1ouDyDln2HcYF+jNaV0xK/Bq4mhIA1xE5TCG1d593faqyaGGrK2WPyUZRBVROzU5LdsE9ag+3U43mbjf27EKQqVRmaWONrHPdx/K6N8uTZwYheIalfqvow6I8sUTR+"; mail-complaints-to="abuse@albasani.net"
X-Mailer Perl5 Mail::Internet v2.05
X-Submission-Address std-cpp-submit@vandevoorde.com
Cancel-Lock sha1:f5HTLqzMoFhdkgjZM16nmsXFx2A=
X-Original-Date Tue, 13 Sep 2011 14:29:59 -0400
Xref x330-a1.tempe.blueboxinc.net comp.std.c++:294

Show key headers only | View raw


on Tue Jun 07 2011, itcecsa<itcecsa-AT-gmail.com>  wrote:

>  to be used in multi-threaded environment, all the containers must be used in
>  a wrapped thread-safe mechanism. is there a thread-safe STL container
>  library existing? or the next C++ standard will support thread-safe
>  containers?

They are exactly as thread-safe as ints are.  [If you're wondering how
it's possible to be less thread-safe than int, consider a type where
copies of an object share some mutable state with it].

Also, adding locking at container granularity is generally wasteful,
because when you want to compose two containers into a larger data
structure, the locking doesn't compose in any useful way.  If there's
some invariant between the containers (say, they always have equal
length), then broken invariants will be exposed to other threads unless
you add an additional layer of locking... at which point the inner locks
are wasted.

Cheers,

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


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

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

STL containers are not thread-safe!  itcecsa <itcecsa@gmail.com> - 2011-06-07 13:04 -0600
  Re: STL containers are not thread-safe!  Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-06-07 14:33 -0600
  Re: STL containers are not thread-safe!  Anthony Williams <anthony.ajw@gmail.com> - 2011-06-07 14:41 -0600
  Re: STL containers are not thread-safe!  cpp4ever <n2xssvv.g02gfr12930@ntlworld.com> - 2011-06-08 13:13 -0600
  Re: STL containers are not thread-safe! Dave Abrahams<dave@boostpro.com> - 2011-09-14 11:15 -0700

csiph-web