std::packaged_task<R(Args...)>::reset
提供: cppreference.com
< cpp | thread | packaged task
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){returnstd::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