This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

1033. thread::join() effects?

Section: 33.4.3.6 [thread.thread.member] Status: C++11 Submitter: Alberto Ganesh Barbati Opened: 2009-03-12 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [thread.thread.member].

View all issues with C++11 status.

Discussion:

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?

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

[ 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.

[ 2009-11-18 Anthony provides wording. ]

[ 2010-02-12 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Proposed resolution:

Edit 33.4.3.6 [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 (6.9.2 [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 ...