One of my coworkers claims that as soon as an object's destructor invocation begins, all accesses to the object's members done by a thread (that's a member of the object itself) are UB.
This implies that calling
// Capturing 'this' is part of the issue.
// The idea is that accessing 'this->x' becomes invalid as soon as '~A()' is entered.
A() : t([this]
x = false;
This is not undefined behavior. If we look at [class.dtor]/8 we have
After executing the body of the destructor and destroying any automatic objects allocated within the body, a destructor for class X calls the destructors for X’s direct non-variant non-static data members, the destructors for X’s direct base classes and, if X is the type of the most derived class (12.6.2), its destructor calls the destructors for X’s virtual base classes.
which states the the non-static members of the class are destroyed after the body of the destructor is ran. That means all the members are alive in the destructor and manipulating
x and calling
join behave just like they would in a normal member function. The only difference is after the body of the destructor is ran then the members themselves will be destroyed.