Title
thread::join() effects?
Status
c++11
Section
[thread.thread.member]
Submitter
Alberto Ganesh Barbati

Created on 2009-03-12.00:00:00 last changed 162 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Edit [thread.thread.member] as indicated:

void join();

5 Precondition: joinable() is true.

Effects: Blocks until the thread represented by *this has completed.

6 Synchronization: The completion of the thread represented by *this happens before ([intro.multithread]) join() returns. [Note: Operations on *this are not synchronized. — end note]

7 Postconditions: If join() throws an exception, the value returned by get_id() is unchanged. Otherwise, The thread represented by *this has completed. get_id() == id().

8 ...

Date: 2009-11-18.00:00:00

[ 2009-11-18 Anthony provides wording. ]

Date: 2010-10-21.18:28:33

[ Batavia (2009-05): ]

Pete believes there may be some more general language (in frontmatter) that can address this and related issues such as 962.

Move to Open.

Date: 2010-10-21.18:28:33

[ See the thread starting at c++std-lib-23204 for more discussion. ]

Date: 2009-03-12.00:00:00

While looking at thread::join() I think I spotted a couple of possible defects in the specifications. I could not find a previous issue or NB comment about that, but I might have missed it.

The postconditions clause for thread::join() is:

Postconditions: If join() throws an exception, the value returned by get_id() is unchanged. Otherwise, get_id() == id().

and the throws clause is:

Throws: std::system_error when the postconditions cannot be achieved.

Now... how could the postconditions not be achieved? It's just a matter of resetting the value of get_id() or leave it unchanged! I bet we can always do that. Moreover, it's a chicken-and-egg problem: in order to decide whether to throw or not I depend on the postconditions, but the postconditions are different in the two cases.

I believe the throws clause should be:

Throws: std::system_error when the effects or postconditions cannot be achieved.

as it is in detach(), or, even better, as the postcondition is trivially satisfiable and to remove the circular dependency:

Throws: std::system_error if the effects cannot be achieved.

Problem is that... ehm... join() has no "Effects" clause. Is that intentional?

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg406
2010-10-21 18:28:33adminsetmessages: + msg405
2010-10-21 18:28:33adminsetmessages: + msg404
2010-10-21 18:28:33adminsetmessages: + msg403
2009-03-12 00:00:00admincreate