0
클래스에 std :: async 개체를 만들면 해당 스레드가 얼마나 오래 실행됩니까? 클래스를 포함하는 클래스의 Desctructor가 호출 될 때까지는?std :: async 실행 시간은 얼마나됩니까?
class Bar {
public:
Bar() {
handle = std::async(
std::launch::async,
&Bar:foo, this);
}
...
void Foo() {
while (true) {//do stuff//}
}
private:
std::future<void> handle;
};
편집 :
긴 다음 예에서 스레드 실행하지 어떻게:
class Bar {
public:
Bar() : thread(&Bar:foo, this) {
}
...
void Foo() {
while (true) {//do stuff//}
}
private:
std::thread thread;
};
감사합니다. 매우 통찰력이 있습니다. 정규식 작업 (예 : 정리)에 대한 함수 Foo가 std :: async 대신 std :: threads를 사용해야한다고 올바르게 이해하고 있습니까? – user695652
C++ 표준에 따르면 컴파일러는 무한정 실행될 스레드를 종료하거나 최적화 할 수 있습니다. – rubenvb