Difference between revisions of "CPP/Boost/ThreadsMember"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==ThreadsMember.cxx== <source lang="cpp"> #include <iostream> #include <vector> #include <cstdlib> #include <cmath> #include <boost/thread.hpp> #include <boost/bind.hpp> using …')
 
(ThreadsMember.cxx)
Line 36: Line 36:
  
 
double temp;
 
double temp;
for(unsigned int i = 0; i < BigNum; i++)
+
for(unsigned int i = 1; i < BigNum; i++)
 
{
 
{
 
temp = sin(i) / i;
 
temp = sin(i) / i;
 +
cout << "\r" << setw(10) << i << setw(10) << temp;
 +
cout.flush();
 
}
 
}
 
cout << "End LongFunction" << endl;
 
cout << "End LongFunction" << endl;

Revision as of 21:48, 23 November 2010

ThreadsMember.cxx

#include <iostream>
#include <vector>
#include <cstdlib>
 
#include <cmath>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
 
using namespace std;
 
class Test
{
	public:
	void LongFunction();
};
 
 
int main(int argc, char* argv[])
{
	Test MyTest;
	boost::thread MyThread(boost::bind(&Test::LongFunction, MyTest));
 
	cout << endl << "Stuff in main" << endl;
 
	MyThread.join();
 
	return 0;
}
 
void Test::LongFunction()
{
	cout << "Start LongFunction" << endl;
	unsigned int BigNum = 1e7;
 
	double temp;
	for(unsigned int i = 1; i < BigNum; i++)
	{
		temp = sin(i) / i;
		cout << "\r" << setw(10) << i << setw(10) << temp;
		cout.flush();
	}
	cout << "End LongFunction" << endl;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(BoostThreads)
 
ADD_EXECUTABLE(BoostThreadsMember BoostThreadsMember.cpp)
TARGET_LINK_LIBRARIES(BoostThreadsMember boost_thread-mt)