Я хочу понять, как работать с std::thread
. Большинство std::thread
учебных пособий выглядит так
void foo() { ... }
....
std::thread thread(foo);
....
thread.join();
Хорошо, я понимаю, что мы можем указать, какая функция прикреплена к потоку в конструкторе. Но есть ли у нас другой путь?
Другими словами, что мне нужно вставить, чтобы запустить t3
thread?
#include <thread>
#include <iostream>
void print(const char* s){
while (true)
std::cout << s <<'\n';
}
int main() {
std::thread t1(print, "foo");
std::thread *t2;
t2 = new std::thread(print, "bar");
std::thread t3; // Don't change this line
// what I need to put here to run t3 ?
t1.join();
t2->join();
t3.join();
delete t2;
return 0;
}