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


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

Is `std::ios_base::xalloc' free from data races?

From Ai Azuma<ai.azuma@gmail.com>
Newsgroups comp.std.c++
Subject Is `std::ios_base::xalloc' free from data races?
Date 2012-06-24 00:03 -0700
Organization http://groups.google.com
Message-ID <cb0a27fd-045d-4ebd-82b2-992076bf648c@oo8g2000pbc.googlegroups.com> (permalink)

Show all headers | View raw


Hi folks,

I have a question about the data-race-freedom of
`std::ios_base::xalloc'.

`std::ios_base::xalloc' has to read and modify an internal counter
object that is shared among threads. So, the implementation has to
synchronize the operations on the counter object, otherwise it may
introduce data races.

I believe that the standard wording implicitly specifies `xalloc' is
free from data races, because the internally used shared counter
object "is not visible to users and is protected against data
races" (quoted from 17.6.5.9/7).

However, `std::ios_base::index' is declared to be `static int' (marked
with "exposition only") in 27.5.3 (`std::ios_base' definition), and
27.5.3.5/1 says that `xalloc' returns `index++'. Therefore,
straightforward reading of these paragraphs falls into the conclusion
that concurrent invocations of `xalloc' may introduce data races.

Which is the intent of the standard, then?

If the former interpretation (i.e., `xalloc' is free from data races)
is the intent of the standard, some editorial modifications (e.g.,
declaring `std::ios_base::index' to be `static std::atomic_int'
instead of `static int' in 27.5.3) would make the wording much
clearer.

I would like to hear from experts. Thank you in advance for your help.


-- 
[ 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 | NextNext in thread | Find similar


Thread

Is `std::ios_base::xalloc' free from data races? Ai Azuma<ai.azuma@gmail.com> - 2012-06-24 00:03 -0700
  Re: Is `std::ios_base::xalloc' free from data races? Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-06-24 23:48 -0700
    Re: Is `std::ios_base::xalloc' free from data races? Ai Azuma<ai.azuma@gmail.com> - 2012-06-25 08:45 -0700

csiph-web