Difference between revisions of "CPP/Boost/Threads"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==Threads.cpp== <source lang="cpp"> #include <iostream> #include <vector> #include <cstdlib> #include <cmath> #include <boost/thread.hpp> void LongFunction(); int main(int a…') |
(→Threads.cpp) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 29: | Line 29: | ||
double temp; | double temp; | ||
− | for(unsigned int i = | + | for(unsigned int i = 1; i < BigNum; i++) |
{ | { | ||
temp = sin(i) / i; | temp = sin(i) / i; | ||
+ | std::cout << "\r" << std::setw(10) << i << std::setw(10) << temp; | ||
+ | std::cout.flush(); | ||
} | } | ||
std::cout << "End LongFunction" << std::endl; | std::cout << "End LongFunction" << std::endl; | ||
} | } | ||
+ | |||
+ | </source> | ||
+ | |||
+ | ==CMakeLists.txt== | ||
+ | <source lang="cmake"> | ||
+ | cmake_minimum_required(VERSION 2.6) | ||
+ | |||
+ | Project(BoostThreads) | ||
+ | |||
+ | ADD_EXECUTABLE(BoostThreads BoostThreads.cpp) | ||
+ | TARGET_LINK_LIBRARIES(BoostThreads boost_thread-mt) | ||
</source> | </source> |
Latest revision as of 07:36, 24 February 2011
Threads.cpp
#include <iostream> #include <vector> #include <cstdlib> #include <cmath> #include <boost/thread.hpp> void LongFunction(); int main(int argc, char* argv[]) { std::cout << "Main: Before thread call" << std::endl; boost::thread MyThread(&LongFunction); std::cout << "Main: After thread call" << std::endl; MyThread.join(); return 0; } void LongFunction() { std::cout << "Start LongFunction" << std::endl; unsigned int BigNum = 1e7; double temp; for(unsigned int i = 1; i < BigNum; i++) { temp = sin(i) / i; std::cout << "\r" << std::setw(10) << i << std::setw(10) << temp; std::cout.flush(); } std::cout << "End LongFunction" << std::endl; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) Project(BoostThreads) ADD_EXECUTABLE(BoostThreads BoostThreads.cpp) TARGET_LINK_LIBRARIES(BoostThreads boost_thread-mt)