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 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: 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 on Tue Jun 07 2011, itcecsa 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 ]