std::packaged_task<R(Args...)>::reset
提供: cppreference.com
<tbody>
</tbody>
void reset(); |
(C++11以上) | |
以前の実行の結果を放棄して状態をリセットします。 新しい共有状態が構築されます。
*this = packaged_task(std::move(f)) と同等です。 ただし f は格納されているタスクです。
引数
(なし)
戻り値
(なし)
例外
*thisが共有状態を持っていない場合 std::future_error。 エラーコンディションは no_state に設定されます。- 新しい共有状態のための十分なメモリがなかった場合 std::bad_alloc。
- 新しい
packaged_taskのムーブコンストラクタによって投げられるあらゆる例外。
例
Run this code
#include <iostream>
#include <cmath>
#include <thread>
#include <future>
int main()
{
std::packaged_task<int(int,int)> task([](int a, int b) {
return std::pow(a, b);
});
std::future<int> result = task.get_future();
task(2, 9);
std::cout << "2^9 = " << result.get() << '\n';
task.reset();
result = task.get_future();
std::thread task_td(std::move(task), 2, 10);
task_td.join();
std::cout << "2^10 = " << result.get() << '\n';
}
出力:
2^9 = 512
2^10 = 1024