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

推荐订阅源

T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
量子位
Martin Fowler
Martin Fowler
月光博客
月光博客
P
Proofpoint News Feed
博客园_首页
Y
Y Combinator Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
H
Help Net Security
U
Unit 42
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 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)  评论()    收藏  举报