[cfe-dev] Possible noncompliance in libc++ std::thread::join()

Howard Hinnant hhinnant at apple.com
Sun Dec 16 15:03:50 PST 2012


On Dec 16, 2012, at 5:50 PM, Gordon Henriksen <gordonhenriksen at me.com> wrote:

> This test fails with libc++ std::thread. Is libc++ or the test in error?
> 
>  TEST(ThreadTests, InvalidNullJoin) {
>    error_code ec;
>    try {
>      thread().join();
>    } catch (system_error &se) {
>      ec = se.code();
>    }
>    EXPECT_EQ(ec, errc::invalid_argument); // no_such_process w/ libc++
>  }
> 
> N3242 §30.3.1.5 reads:
> 
>    void join();
>    ...
> 
>    Error conditions:
> 
>      — resource_deadlock_would_occur — if deadlock is detected or
>        this->get_id() == std::this_thread::get_id().
> 
>      - no_such_process — if the thread is not valid.
> 
>      - invalid_argument — if the thread is not joinable.

The thread is neither valid nor joinable.  When I do this:

#include <thread>
#include <iostream>

int main()
{
    try
    {
        std::thread().join();
    }
    catch (const std::exception& e)
    {
        std::cout << e.what() << '\n';
    }
}

I get this:

thread::join failed: No such process

This is the error that the OS returns for this operation (join called on a non-existent thread).  This looks conforming to me.

Howard





More information about the cfe-dev mailing list