//thread is a new feature of c++11 standard
#include <iostream>
#include <thread>
using namespace std;
void threadFun()
{
cout << "hi from thread \n";
}
int main()
{
thread th(&threadFun);
cout << "hi from main \n";
th.join();
return 0;
}
//this program to show parallel programming
// using lamda function
#include <iostream>
#include <thread>
using namespace std;
int main()
{
thread th([]()
{
cout << "hi from thread \n";
}
);
cout << "hi from main \n";
th.join();
return 0;
}
Run these program and see the beauty of thread. (most sexiest output you have ever seen before.)
Note: For thread library support in c++ you require latest complier
for further information see Thread support library.
#include <iostream>
#include <thread>
using namespace std;
void threadFun()
{
cout << "hi from thread \n";
}
int main()
{
thread th(&threadFun);
cout << "hi from main \n";
th.join();
return 0;
}
//this program to show parallel programming
// using lamda function
#include <iostream>
#include <thread>
using namespace std;
int main()
{
thread th([]()
{
cout << "hi from thread \n";
}
);
cout << "hi from main \n";
th.join();
return 0;
}
Run these program and see the beauty of thread. (most sexiest output you have ever seen before.)
Note: For thread library support in c++ you require latest complier
- In linux GCC 4.6 or higher
- In windows Visual c++ 2012 or MinGw64, (MinGw32 yet not able to compile thread program)
for further information see Thread support library.
No comments:
Post a Comment