Abort problem, sigslot::observer and thread will generate coredump. Should signals and slots solve this life cycle problem?
TgeaUs opened this issue · comments
TgeaUs commented
g++ 9.4.0
ubuntu 5.15.0
class Obj : public sigslot::observer
{
public:
void sx()
{
std::cout << "sm() id = " << std::this_thread::get_id() << std::endl;
}
};
int main()
{
sigslot::signal<> sig;
{
Obj obj;
sig.connect(&Obj::sx, &obj);
std::thread t([&sig]
{
sig();
});
// no join
}
}
Pierre-Antoine Lacaze commented
Hi,
A core dump is the standard behavior for std::thread when a joinable thread gets destroyed before a call to join(). Either call detach(), join the thread or use std::jthread instead.
Lifetime management is out of the scope of Sigslot. The library gives a few options to help with lifetime, but it cannot provide tools for every situation.