Created
November 30, 2018 07:33
-
-
Save kgbook/d49191e3b67d5f8fc0766a7d39f98d79 to your computer and use it in GitHub Desktop.
[boost thread interruption example] boost thread interruption example #boost::thread::interrupt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/thread.hpp> | |
using std::cout; | |
using std::endl; | |
void sayHello() { | |
int32_t cnt = 0; | |
while (!boost::this_thread::interruption_requested()) { | |
cout <<"hello! " <<++cnt <<endl; | |
} | |
cout <<"thread terminate!" <<endl; | |
} | |
int main() { | |
boost::thread thread(&sayHello); | |
sleep(1); | |
thread.interrupt(); | |
thread.join(); | |
cout <<"exit!" <<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment