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::make_ready_at_thread_exit(3) C++ Standard Libary std::packaged_task::make_ready_at_thread_exit(3)

std::packaged_task::make_ready_at_thread_exit - std::packaged_task::make_ready_at_thread_exit


void make_ready_at_thread_exit( ArgTypes... args ); (since C++11)


Calls the stored task with forwarded args as the arguments. The return value of the
task or any exception thrown by it is stored in the shared state of *this.


The shared state is only made ready after the current thread exits and all objects
of thread local storage duration are destroyed.


args - the parameters to pass on invocation of the stored task


(none)


std::future_error on the following error conditions:


* The stored task has already been invoked. The error category is set to
promise_already_satisfied.
* *this has no shared state. The error category is set to no_state.

// Run this code


#include <future>
#include <iostream>
#include <chrono>
#include <thread>
#include <functional>
#include <utility>


void worker(std::future<void>& output)
{
std::packaged_task<void(bool&)> my_task{ [](bool& done) { done=true; } };


auto result = my_task.get_future();


bool done = false;


my_task.make_ready_at_thread_exit(done); // execute task right away


std::cout << "worker: done = " << std::boolalpha << done << std::endl;


auto status = result.wait_for(std::chrono::seconds(0));
if (status == std::future_status::timeout)
std::cout << "worker: result is not ready yet" << std::endl;


output = std::move(result);
}


int main()
{
std::future<void> result;


std::thread{worker, std::ref(result)}.join();


auto status = result.wait_for(std::chrono::seconds(0));
if (status == std::future_status::ready)
std::cout << "main: result is ready" << std::endl;
}


worker: done = true
worker: result is not ready yet
main: result is ready


operator() executes the function
(public member function)

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.