palacaze / sigslot

A simple C++14 signal-slots implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Abort problem, sigslot::observer and thread will generate coredump. Should signals and slots solve this life cycle problem?

TgeaUs opened this issue · comments

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
    }
}

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.