#include
#include
void task1() {
// do stuff
std::cout << "This is task1!" << std::endl;
}
void task2() {
// do stuff
std::cout << "This is task2!" << std::endl;
}
int main (int argc, char ** argv) {
using namespace boost;
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);
// do other stuff
thread_2.join(); //阻塞调用
thread_1.detach();// 分离调用,如果采用detach,则子线程会随主线程一起结束,此时你需要让主线程晚于子线程结束,可以slepp下。
return 0;
}
g++ -I./inlcude -L./usr/lib64 test_thread.cpp -lboost_thread-mt -o test
阅读(1514) | 评论(0) | 转发(0) |