如何将async与不返回任何内容的lambdas一起使用

How to use async with lambdas which does not return anything?

本文关键字:lambdas 一起 任何内 返回 async      更新时间:2023-10-16

我在async内部调用了一个简单的lambda。但它给出了一个系统错误。

#include<future>
#include<iostream>
int main()
{
    auto a = std::async([]()
    {
        std::cout << 42 << std::endl;
    });
    a.get();
    return 0;
}

http://ideone.com/GIyGI

编译器:C++0x(gcc-4.5.1)

有什么想法吗?

很可能,您需要使用-pthread选项进行编译。