How to start a new jthread on a class member
06:10 01 Feb 2022

I think the question is quite obvious. The I have tried so far:

#include 
#include 

using namespace std::literals::chrono_literals;

class test
{
public:
    void member(std::stop_token stoken)
    {
        std::this_thread::sleep_for(1s);
    }

    void run()
    {
        // None compiles correctly
        // std::jthread jt(&member);
        // std::jthread jt(&test::member, this);
    }
};

int main()
{
    test t;
    t.run();

    return 0;
}

Is it possible with the new jthread & with using stop_token? Ps.: Of course it's possible to workaround it by making the member function static or by removing the stop_token. But I'm curious if there's a real & clean solution instead of extra N lines of hacking.

c++ multithreading c++20