Difference between revisions of "CPP/Boost/Threads"
From ProgrammingExamples
< CPP
(→Threads.cpp) |
(→Threads.cpp) |
||
(One intermediate revision by one other user not shown) | |||
Line 32: | Line 32: | ||
{ | { | ||
temp = sin(i) / i; | temp = sin(i) / i; | ||
− | std::cout << "\r" << std::setw(10) << i << setw(10) << temp; | + | std::cout << "\r" << std::setw(10) << i << std::setw(10) << temp; |
std::cout.flush(); | std::cout.flush(); | ||
} | } | ||
Line 38: | Line 38: | ||
} | } | ||
+ | |||
+ | </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)