Difference between revisions of "CPP/Boost/Threads"
From ProgrammingExamples
< CPP
(→Threads.cpp) |
Daviddoria (Talk | contribs) |
||
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> |
Revision as of 11:47, 23 January 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 << 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)