#include "pch.h"
#include <iostream>
#include <thread>
using namespace std;
void myPrint(const int& i, char * buf)
{
//++i;
cout << i << endl;
cout << buf << endl;
return;
}
int main()
{
//int v = 1;
//int &va = v;
//const char *buf = "this is a test!";
////myPrint(v, buf);
//thread mytobj(myPrint, v, buf);
////mytobj.join();
//mytobj.detach();
// std::cout << "Hello World!\n" << v;
int v = 1;
int &va = v;
char buf[] = "this is a test!";
//myPrint(v, buf);
thread mytobj(myPrint, v, buf);
//mytobj.join();
mytobj.detach();
std::cout << "Hello World!\n" << v;
}
#include "pch.h"
#include <iostream>
#include <thread>
using namespace std;
class MyClass
{
public:
int i;
MyClass(int i) :i(i)
{
cout << "construct function exec " << endl;
}
MyClass(const MyClass &a) :i(a.i) { cout << "copy construct function exec " << endl; }
~MyClass()
{
cout << "disconstruct function exec " << endl;
}
private:
};
void myPrint(const int& i, const MyClass buf)
{
//++i;
cout << i << endl;
cout << &buf << endl;
return;
}
int main()
{
//int v = 1;
//int &va = v;
//const char *buf = "this is a test!";
////myPrint(v, buf);
//thread mytobj(myPrint, v, buf);
////mytobj.join();
//mytobj.detach();
// std::cout << "Hello World!\n" << v;
int v = 1;
int &va = v;
char buf[] = "this is a test!";
//myPrint(v, buf);
thread mytobj(myPrint, v, MyClass(v));
//mytobj.join();
mytobj.detach();
//std::cout << "Hello World!\n" << v;
}
网友评论