GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::packaged_task::reset(3) C++ Standard Libary std::packaged_task::reset(3)

std::packaged_task::reset - std::packaged_task::reset


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.


(none)


(none)


* std::future_error if *this has no shared state. The error condition is set to
no_state.
* std::bad_alloc if there was not enough memory for a new shared state.
* any exception thrown by the move constructor of the new 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

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.