代码如下:

/////////////////////////////////////////////////
//        
//
//            C++11 async test
//
//

#include "pch.h"
#include <iostream>

#include <future>

struct Task
{
    int operator () (int i)
    {
        std::cout << "task run" << std::endl;
        return i + 10;
    }
};

int main(int argc, char * const argv[])
{
    Task t;
    std::future<int> result = std::async(std::launch::async, t, 16);
    for (int i = 0; i < 100; ++i)
    {
        std::cout << "main thread" << std::endl;
    }
    std::cout << result.get() << std::endl;

    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-10-09
  • 2021-07-14
  • 2021-11-05
  • 2023-03-08
  • 2021-07-03
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2021-05-21
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案