Namespaces
Variants
Actions

std::packaged_task<R(Args...)>::reset

From cppreference.com
< cpp‎ | thread‎ | packaged task
 
 
Concurrency support library
(C++11)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++17)
(C++11)
(C++11)
(C++17)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)
(C++11)
(C++20)
(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++26)
(C++26)
(C++26)
(C++26)
(C++11)
(C++20)
(C++11)
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
(C++11)
(C++11)(deprecated in C++26)
 
 
void reset();
(since C++11)

Resets the state abandoning the results of previous executions. New shared state is constructed.

Equivalent to *this = packaged_task(std::move(f)), where f is the stored task.

[edit] Parameters

(none)

[edit] Return value

(none)

[edit] Exceptions

[edit] Example

Run this code
#include <cmath>
#include <future>
#include <iostream>
#include <thread>
 
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';
}

Output:

2^9 = 512
2^10 = 1024
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/packaged_task/reset&oldid=161201"

AltStyle によって変換されたページ (->オリジナル) /