The weird problem using void alarmHandler(int signal_number)

I am writing an "void alarmHandler(int signal_number)" to register the signal SIGALRM.

The handler is :

void alarmHandler(int signal_number)
{
static int a = 0;

a= a+1;

if (a == 9)
{
pthread_kill(tid, A);
}

else
{
if (a % 2 == 0)
{

alarm(5);
pthread_kill(tid, B);
}

else if (a % 2 == 1)
{
pthread_kill(tid, C);
alarm(10);
}
}

signal(signal_number, alarmHandler); // re-register with the signal service
}

Then I found a weird problem that counter varibale "a" will increase to 2, one by one, then directly go to 11. I use gdb to run it step by step, it works well. But when I run it without gdb, it just performed weird. Anyone has idea why? What the reason can cause the static variable a increase to 11 from 2 directly?

Thanks very much in advance.
post a minimal snip that does reproduce your problem
Topic archived. No new replies allowed.