0
クラスでstd :: asyncオブジェクトを作成した場合、対応するスレッドはどれくらいの期間実行されますか?収容クラス(Bar)のデストラクタが呼び出されるまでは?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;
};
EDIT:
どのくらい次の例では、スレッドの実行ん:
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