Skip to content

Instantly share code, notes, and snippets.

@kgbook
Created November 30, 2018 07:33
Show Gist options
  • Save kgbook/d49191e3b67d5f8fc0766a7d39f98d79 to your computer and use it in GitHub Desktop.
Save kgbook/d49191e3b67d5f8fc0766a7d39f98d79 to your computer and use it in GitHub Desktop.
[boost thread interruption example] boost thread interruption example #boost::thread::interrupt
#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