A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../thread/shared_future.html below:

std::shared_future - cppreference.com

template< class T > class shared_future;

(1) (since C++11)

template< class T > class shared_future<T&>;

(2) (since C++11)

template<> class shared_future<void>;

(3) (since C++11)

The class template std::shared_future provides a mechanism to access the result of asynchronous operations, similar to std::future, except that multiple threads are allowed to wait for the same shared state. Unlike std::future, which is only moveable (so only one instance can refer to any particular asynchronous result), std::shared_future is copyable and multiple shared future objects may refer to the same shared state.

Access to the same shared state from multiple threads is safe if each thread does it through its own copy of a shared_future object.

[edit] Member functions constructs the future object
(public member function) [edit] destructs the future object
(public member function) assigns the contents
(public member function) Getting the result returns the result
(public member function) [edit] State checks if the future has a shared state
(public member function) [edit] waits for the result to become available
(public member function) [edit] waits for the result, returns if it is not available for the specified timeout duration
(public member function) [edit] waits for the result, returns if it is not available until specified time point has been reached
(public member function) [edit] [edit] Example

A shared_future may be used to signal multiple threads simultaneously, similar to std::condition_variable::notify_all().

Possible output:

Thread 1 received the signal 0.072 ms after start
Thread 2 received the signal 0.041 ms after start
[edit] See also runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result
(function template) [edit] waits for a value that is set asynchronously
(class template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4