Something like this:
auto f = std::async(&Person::sum, &p, xxx);
or
auto f = std::async(std::launch::async, &Person::sum, &p, xxx);
where p
is a Person
instance and xxx
is an int
.
This simple demo works with GCC 4.6.3:
#include <future>
#include <iostream>
struct Foo
{
Foo() : data(0) {}
void sum(int i) { data +=i;}
int data;
};
int main()
{
Foo foo;
auto f = std::async(&Foo::sum, &foo, 42);
f.get();
std::cout << foo.data << "
";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…