惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
J
Java Code Geeks
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
腾讯CDC
博客园 - 司徒正美
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
I
InfoQ
N
Netflix TechBlog - Medium
L
LangChain Blog
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
美团技术团队
The Cloudflare Blog
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Martin Fowler
Martin Fowler
V
Visual Studio Blog

博客园 - Len3d

Audacity录音+混响初步经验 专辑歌曲列表 奇迹 找到你 下弦月 研报和信息查询网站 研报查询链接 徒手画个disk不容易啊。。。 fast powf SSE sqrt还是比C math库的sqrtf快了不少 Mongoose也是个大坑 A tiny program to benchmark image transpose algorithms On extracting ops from LLVM backend Into concurrent LRU caching once again 性能大坑 多项式在线拟合神器 iOS app开发资料整理 完美的视图旋转算法 Windows上使用clang编译 nodejs Rpath handling on Linux C++ Web Service SDK Fast integer math tricks for C Point in polygon algorithm C code
初步测试了一下C++11的async/future
Len3d · 2020-06-28 · via 博客园 - Len3d

代码如下:

/////////////////////////////////////////////////
//        
//
//            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;
}

posted on 2020-06-28 13:26  Len3d  阅读(321)  评论()    收藏  举报