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


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

Re: STL containers are not thread-safe!

From Dave Abrahams<dave@boostpro.com>
Newsgroups comp.std.c++
Subject Re: STL containers are not thread-safe!
Date 2011-09-14 11:15 -0700
Organization unknown
Message-ID <m2d3f4e1nc.fsf@pluto.luannocracy.com> (permalink)
References <7b4b5352-05a4-436e-8c57-aa51d4116428@glegroupsg2000goo.googlegroups.com>

Show all headers | 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