3 Replies Latest reply on Apr 26, 2016 1:24 PM by Intel Corporation

    Strange behaviour of Timer Interrupts on Intel Edison




      I found myself facing a strange problem when testing Linux timer interrupts on Intel Edison as suggested in Create your own timer routine in Linux | My Linux and Telecom Experiences.

      This is my test code:

      #include "mraa.h"
      #include <sys/time.h>
      #include <iostream>
      #include <fstream>
      #include <unistd.h>
      #include <signal.h>
      #include <string.h>
      using namespace std;
      struct itimerval timer;
      bool test = false;
      void sigalrm_handler(int signum);
      struct timespec startTime;
      struct timespec endTime;
      int main () {
        timer.it_value.tv_sec = 5;
        timer.it_value.tv_usec = 0;
        timer.it_interval.tv_sec = 5;
        timer.it_interval.tv_usec = 0;
        struct sigaction act;
        memset(&act, '\0', sizeof(act));
        act.sa_handler = &sigalrm_handler;
        sigaction(SIGTERM, &act, NULL);
        setitimer(ITIMER_REAL, &timer, NULL);
      void sigalrm_handler(int signum){
        cout<<"handler executed"<<endl;
        test = true;

      Strangely, this code does not work as the interrupt handler never get executed and the program keeps outputting "working..." in my test. but if you comment out line 31 and have a empty while loop, the timer works perfectly. The same bahaviour happens if I use the deprecated signal() function.

      Has anyone else faced this problem before? Did I do something wrong in my code? I tried to search online but all resources that I found seem to suggest that this should work.

      Thanks in advance.


      Best Regards