Monday, 30 March 2009
The March 2009 mailing for the C++ Standards Committee was published last week. This mailing contains the results of the first round of National Body voting on the C++0x draft, as well as the latest version of the C++0x working draft. This latest draft includes some changes in response to these NB comments, as agreed at the committee meeting at the beginning of March. Some of the changes related to concurrency and the thread library are listed below. The state of all comments (accepted, rejected, or unprocessed) can be found in N2863: C++ CD1 comment status.
The committee is intending to address all the comments (which may include rejecting some, as has already happened) in time to publish a second draft for National Body comments by the end of the year. If there is sufficient consensus on that draft, it will become the C++0x standard, otherwise it will have to undergo another round of revisions.
The atomics library has only seen one accepted change so far, and that's a result of US issue 91: a failed compare_exchange operation is only atomic load rather than a read-modify-write operation. This should not have any impact on code that uses atomics, but can enable the implementation to be optimized on some architectures. The details can be seen in LWG issue 1043.
On the other hand, the thread library has seen a couple of accepted changes which will have user-visible consequences. These are:
- Hans Boehm's paper N2082:
A plea to reconsider detach-on-destruction for thread objects, was
reviewed as part of US issue 97. The result is that if you do not
std::threadobjects before they are destroyed then the library will call
std::terminate(). This is to ensure that there are no unintentional "dangling threads" with references to local variables.
std::unique_lockno longer have
swap()functions that operate on rvalues
- This change is in response to US issue 46, and the associated
Fixing a Safety Problem with Rvalue References: Proposed Wording
(Revision 1), which changes the way the rvalue-references work. In
particular, an rvalue-reference no longer binds to an lvalue. Combined
with the previous change to disallow destroying
std::threadobjects with an associated thread of execution this makes perfect sense: swapping two rvalue
std::threadobjects serves no purpose anyway, and swapping a
std::threadvariable with an rvalue would now call
std::terminate()when the rvalue is destroyed at the end of the expression, if the variable had an associated thread of execution.
- The single-argument
std::threadconstructor has been removed
- This was UK issue 323. The variadic
std::threadconstructor provides all the necessary functionality.
There are also a few minor concurrency-related changes that have
been approved, mostly along the lines of clarifying the text. There
are a few more which are still under discussion, one of which is quite
significant: UK issue 329. This comment proposes the addition of a new
std::async() which will execute a function
asynchronously and return a
std::unique_future which can
be used to obtain the result. Details can be seen under LWG