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

std::future::wait - std::future::wait


void wait() const; (since C++11)


Blocks until the result becomes available. valid() == true after the call.


The behavior is undefined if valid() == false before the call to this function.


(none)


(none)


May throw implementation-defined exceptions.


The implementations are encouraged to detect the case when valid() == false before
the call and throw a std::future_error with an error condition of
std::future_errc::no_state.

// Run this code


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


int fib(int n)
{
if (n < 3) return 1;
else return fib(n-1) + fib(n-2);
}


int main()
{
std::future<int> f1 = std::async(std::launch::async, [](){
return fib(40);
});
std::future<int> f2 = std::async(std::launch::async, [](){
return fib(43);
});


std::cout << "waiting... " << std::flush;
const auto start = std::chrono::system_clock::now();


f1.wait();
f2.wait();


const auto diff = std::chrono::system_clock::now() - start;
std::cout << std::chrono::duration<double>(diff).count() << " seconds\n";


std::cout << "f1: " << f1.get() << '\n';
std::cout << "f2: " << f2.get() << '\n';
}


waiting... 1.61803 seconds
f1: 102334155
f2: 433494437


waits for the result, returns if it is not available for the specified
wait_for timeout duration
(public member function)
waits for the result, returns if it is not available until specified time
wait_until point has been reached
(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.