logo
  • 教程列表
  • SO官方文檔
  • 期貨和承諾
    • stdfuture 和 stdpromise
    • 延遲非同步示例
    • stdpackaged 任務和 stdfuture
    • stdfuture 錯誤和 stdfuture errc
    • stdfuture 和 stdasync
    • 非同步操作類
  1. StackOverflow 文件
  2. C++ 教程
  3. 期貨和承諾
  4. stdfuture 和 stdpromise

stdfuture 和 stdpromise

Created: November-22, 2018

以下示例設定另一個執行緒使用的承諾:

    {
        auto promise = std::promise<std::string>();
        
        auto producer = std::thread([&]
        {
            promise.set_value("Hello World");
        });
        
        auto future = promise.get_future();
        
        auto consumer = std::thread([&]
        {
            std::cout << future.get();
        });
        
        producer.join();
        consumer.join();
}
  • 延遲非同步示例
  • 期貨和承諾

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明