点击(此处)折叠或打开
- #include <iostream>
- #include <cassert>
- #include <string>
- #include <iomanip>
- #include <boost/thread/thread.hpp>
- #include "boost/regex.hpp"
- using namespace std;
- void print_hello(void){
- while(1){
- std::cout<<"hello\n"<<std::endl;
- std::cout<<pthread_self()<<std::endl;
- sleep(1);
- }
- }
- void print_nice(void){
- while(1){
- std::cout<<"nice\n"<<std::endl;
- std::cout<<pthread_self()<<std::endl;
- usleep(500000);
- }
- }
- int main(int argc,char *argv[]) {
- int i;
- i=10;
- std::cout<<std::endl;
- boost::thread thread1(&print_hello);
- boost::thread thread2(&print_nice);
- cout<<dec<<i<<" "<<hex<<i<<endl;
- cout<<dec<<thread1.get_id()<<std::endl;
- cout<<dec<<thread2.get_id()<<std::endl;
- thread1.join();
- thread2.join();
- return true;
- }