#include<iostream>
#include<thread>
#include<mutex>
using namespace std;
class Listener {
public:
Listener() {};
~Listener() {};
void onStart() {
cout << "start" << endl;
}
void onDone(int result) {
cout << "done" << endl;
this->result = result;
}
int get() {
return this->result;
}
private:
int result;
};
void f(Listener &lis)
{
int r = 0;
lis.onStart();
for (int i = 0; i < 10; i++)
{
r += i;
}
lis.onDone(r);
}
int main(int argc, int * argv[])
{
Listener lis;
thread t1(f, std::ref(lis));
t1.join();
cout << lis.get()<< endl;
cout << "main" << endl;
system("pause");
}