- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi
I found myself facing a strange problem when testing Linux timer interrupts on Intel Edison as suggested in https://madalanarayana.wordpress.com/2014/01/25/create-your-own-timer-routine-in-linux/ Create your own timer routine in Linux | My Linux and Telecom Experiences.
This is my test code:
# include "mraa.h"
# include
# include
# include
# include
# include
# include
using namespace std;
struct itimerval timer;
bool test = false;
void sigalrm_handler(int signum);
struct timespec startTime;
struct timespec endTime;
int main () {
cout<<"started"<<endl;
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);
while(!test){
cout<<"working..."<<endl;
}
cout<<test<<endl;
}
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
lyfkyle
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello lyfkyle,
I tested your code on the latest version of Edison's image and it seemed to work just fine. If I'm not mistaken the script should start, write working… for five seconds until the interrupt comes and ends the script, am I right? If so, it's working fine for me, which image are you using to test this?
Peter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Peter,
I just flashed in the latest firmware using the installer version 2016.1.035 and I am still facing the same problem. My code works when I leave the while loop blank but it does not when I add in the cout<<"working..."<<endl. I have also tested with other functions in the while loop, it seems that as long as I am are outputting something to the eclipse console, the timer interrupt will not work. But since I don't have to output anything in my final application, I guess it is fine for me. This problem is a little bit weird though.
Thanks
Lyfkyle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Oh, you are using Eclipse to run your code. That might the cause of the issue. As you can see in the screenshot bellow I tested it directly on Linux and if I'm not mistaken, that is the expected behavior:
Peter.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page