zoukankan      html  css  js  c++  java
  • 33.promise future多线程通信

     1 #define _CRT_SECURE_NO_WARNINGS
     2 #include <iostream>
     3 #include <thread> 
     4 #include <future>
     5 #include <string>
     6 #include <cstdlib>
     7 using namespace std;
     8 
     9 promise <string>val;//全局通信变量
    10 void main()
    11 {
    12     //字符串相加
    13     /*string str1("123");
    14     string str2("34");
    15     string str3(str1 + str2);
    16     cout << str3 << endl;*/
    17 
    18     thread th1([]() 
    19     {
    20         future<string> str = val.get_future();//获取未来状态
    21         cout << "等待中" << endl;
    22         //阻塞等待
    23         cout << str.get() << endl;
    24     }
    25     );
    26 
    27     thread th2([]() 
    28     {
    29         system("pause");
    30         val.set_value("hello");
    31     }
    32     );
    33 
    34     th1.join();
    35     th2.join();
    36     cin.get();
    37 }
  • 相关阅读:
    修改表结构
    enum/set 约束
    MYSQL 数据类型
    表和数据的基础操作
    存储引擎
    mysql
    HTML 介绍
    selor模块
    select
    协程
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8548099.html
Copyright © 2011-2022 走看看