Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory corruption when using SIGALRM and timer
    text
    copied!<p>Ok not really sure if it is memory corruption or just a bug in my code, but here is the description of the problem: Single threaded program registers a SIGALRM handler:</p> <pre><code>struct sigaction action; sigset_t blocked; sigfillset(&amp;blocked); sigdelset(&amp;blocked, SIGKILL); sigdelset(&amp;blocked, SIGSTOP); action.sa_handler = &amp;handler_function; action.sa_flags = SA_RESTART; action.sa_mask = blocked; // We are not interested in the previous action: if (sigaction(SIGALRM, &amp;action, NULL) == -1) .... </code></pre> <p>handler_function is a simple function which calls a function of an object:</p> <pre><code>void handler_function() { some_object-&gt;tick(); } tick() { ++variable; } </code></pre> <p>Variable is of type long. my program has only one instance of some_object and only signal handler calls function tick and only tick function modifies variable. Other functions only read value of variable. Forgot to mention that I create a timer:</p> <pre><code>struct timeval interval; interval.tv_sec = 0; interval.tv_usec = (100000); struct itimerval timer; timer.it_interval = interval; timer.it_value = interval; if (setitimer(ITIMER_REAL, &amp;timer, NULL) == -1) ... </code></pre> <p>so tick function is triggered 10 times per second. Now the problem is that intermittently i get other data members of object some_object corrupted, they are POD types(long), i.e. all of a sudden they contain random values. I've tried to isolate a problem in a small program, but to no avail. Any advise would be appreciated. thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload