Код: Выделить всё
// USING C++ 17
#include
#include
#include
#include
class MyClass {
std::thread thread;
std::string mystring;
public:
bool done = false;
MyClass(std::string string) {
mystring = string;
thread = std::thread(&MyClass::worker, std::ref(*this));
thread.detach();
}
void worker() {
// notice how mystring has the wrong value, some of the time
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78704505/moving-stdthread-with-references[/url]