Перемещение std::thread со ссылкамиC++

Программы на C++. Форум разработчиков
Anonymous
Перемещение std::thread со ссылками

Сообщение Anonymous »

У меня есть класс, в котором есть такой поток:

Код: Выделить всё

// 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]

Вернуться в «C++»