i am currently working on raspberry pi and interfacing an ADC with it. The ADC outputs the digital value continuously. The reading of the value and its processing is initiated and executed in a thread, therefore it should run forever. However in order to exit (for some reason) from the thread cleanly, I want to use SIGINT signal handler, which triggers an interrupt and changes the state of volatile variable. The pseudo-program is as follows:
volatile sig_atomic_t exitThread = 0;
void signalHandler(){
exitThread = 1;
}
void SPI_Port0(){
//initialisation of functions and variables
while(!exitThread){
//do the work
}
if(exitThread){
pthread_exit(NULL);
}
}
void main(){
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = signalHandler;
sigaction(SIGINT, &sa, NULL);
pthread_t SPI0,SPI3;
pthread_create(&SPI0, NULL, SPI_Port0, NULL);
pthread_create(&SPI3, NULL, SPI_Port1, NULL);
pthread_join(SPI0, NULL);
pthread_join(SPI3, NULL);
//printing the results stored in arrays
//the arrays is declared global
}
there are two threads SPI_Port0 and SPI_Port1 doing the same implementation but on two different SPI ports, I want these two threads to exit when the CTRL + C is pressed. The problem i am facing is that, the whole program is exited.
Can someone point me in the right direction. Any help would be appreciated.