Advertisement
obernardovieira

Multi-Thread, Timer e fim de Timer (with boost)

Jun 23rd, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <boost\thread.hpp>
  4.  
  5. boost::thread my_boost_th;
  6.  
  7. void multiprocesso(int id) {
  8.     static int rep=-1;
  9.     boost::this_thread::sleep(boost::get_system_time()+boost::posix_time::milliseconds(1000));
  10.     printf("id - %d",id);
  11.     rep++;
  12.     if(!rep) {
  13.         multiprocesso(id);
  14.     }
  15. }
  16.  
  17. void interrompe() {
  18.     boost::this_thread::sleep(boost::get_system_time()+boost::posix_time::milliseconds(1300));
  19.     my_boost_th.interrupt();
  20. }
  21.  
  22. int main()
  23. {
  24.     my_boost_th=boost::thread(multiprocesso,10);
  25.     boost::thread interronper(interrompe);
  26.     Sleep(5000);
  27.     system("pause");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement