Last active
June 27, 2017 11:37
-
-
Save alepez/61c02a6f031ce60f0b3e19ae27ffd5db to your computer and use it in GitHub Desktop.
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
/* | |
* Example 1: exits on SIGINT | |
*/ | |
#include <iostream> | |
#include <signal.h> | |
#include <unistd.h> | |
bool continueRunning = true; | |
void sighandler(int signum) { | |
continueRunning = false; | |
} | |
int main() { | |
signal(SIGINT, sighandler); | |
while (continueRunning) { | |
usleep(1000); | |
} | |
std::cout << "exit" << std::endl; | |
return 0; | |
} |
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
/* | |
* Example 1: does not exit on SIGINT | |
*/ | |
#include <iostream> | |
#include <signal.h> | |
#include <unistd.h> | |
bool continueRunning = true; | |
void sighandler(int signum) { | |
continueRunning = false; | |
} | |
int main() { | |
signal(SIGINT, sighandler); | |
while (continueRunning) { | |
} | |
std::cout << "exit" << std::endl; | |
return 0; | |
} |
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
/* | |
* Example 1: with volatile, exits on SIGINT | |
*/ | |
#include <iostream> | |
#include <signal.h> | |
#include <unistd.h> | |
volatile bool continueRunning = true; | |
void sighandler(int signum) { | |
continueRunning = false; | |
} | |
int main() { | |
signal(SIGINT, sighandler); | |
while (continueRunning) { | |
} | |
std::cout << "exit" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment