Aug 3, 2012 at 6:34pm UTC
Dear all,
I need to schedule two independant events at the same time, typically, filling two queues simultaneously using a Poisson trafic. This is what I did right now:
void Queue_class::SetPoissonTraficFirstQueue(void)
{ // add one packet to the queue
struct sigaction act ;
struct itimerval timer ;
act.sa_handler = this ;
sigempty_set(&act.sa_mask) ; // no signal is added to the sa_mask
act.sa_flags = 0 ;
sigaction(SIGALARM, &act,0) ;
timer.it_value.tv_usec = 0 ;
timer.it_value.tv_sec = exponential_variable() ; // generates a random exponential variable
timer.it_interval.tv_sec = 0 ;
timer.it_interval.tv_usec = 0 ;
setitimer(ITIMER_REAL, *timer, NULL) ;
}
void Queue_class::SetPoissonTraficSecondQueue(void)
{ // add one packet to the queue
struct sigaction act ;
struct itimerval timer ;
act.sa_handler = this ;
sigempty_set(&act.sa_mask) ; // no signal is added to the sa_mask
act.sa_flags = 0 ;
sigaction(SIGALARM, &act,0) ;
timer.it_value.tv_usec = 0 ;
timer.it_value.tv_sec = exponential_variable() ; // generates a random exponential variable
timer.it_interval.tv_sec = 0 ;
timer.it_interval.tv_usec = 0 ;
setitimer(ITIMER_REAL, *timer, NULL) ;
}
In the main, I do what follows:
int main()
{
Queue_class queue ;
queue.SetPoissonTraficFirstQueue() ;
queue.SetPoissonTraficSecondQueue() ;
// do business
}
I have two question please regarding my code:
1- Is it a good solution to call the function internally with the pointer "this" in sa_handler method?
2- In the main function, do the two processes occur simultaneously as I want: I mean are both queues filled at the same time?
Last edited on Aug 3, 2012 at 6:35pm UTC
Aug 6, 2012 at 6:43pm UTC
1. No -- "this" is not a function pointer.
2. No -- you coded them sequentially and that is how they will run.