Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use promise future in Category 11

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use promise future in Craft 11. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Introduction to the std::promise class

A promise object can hold a value of a type T that can be read by a future object (perhaps in another thread), so promise also provides a means of thread synchronization. When a promise object is constructed, it can be associated with a shared state (usually std::future), and a value of type T can be saved on the associated shared state (std::future).

You can get the future object associated with the promise object through get_future, and after calling this function, the two objects share the same shared state (shared state)

The promise object is an asynchronous Provider that sets the value of the shared state at some point.

The future object can return the value of the shared state asynchronously or, if necessary, block the caller and wait for the shared state flag to change to ready before getting the shared state value.

Here is a simple example to illustrate the above relationship.

# include / / std::cout#include / / std::ref#include / / std::thread#include / / std::promise, std::futurevoid print_int (std::future& fut) {int x = fut.get (); / / get the value of the shared status. Std::cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report