linux - Is using timers/signals in c static libraries bad practice? -
i'm building 2 static c libraries. each of libraries have routine needs run once every second after calling mylib_init();
i implemented in each library using setitimer, uses itimer_real resource , sigalrm signal.
void start1mstimer() { struct itimerval new; memset(&new,0, sizeof(new)); new.it_interval.tv_sec=1; new.it_value.tv_sec=1; signal (sigalrm, onesectimeout); setitimer (itimer_real, &new,null); }
ok far working.
now i'm building sample application uses both of these libraries, , conflicts arising. have realized application can have 1 handler each signal, , itimer_real can used 1 timer, not both. things not working now.
what better way me implement timing in each of libraries?
in general, bad idea have signal handlers inside of library?
you use threads + syncronization method. instead of writing signal handler, write thread. using semaphore, can run event thread either on timeout or on demand (ie app calls library function post semaphore).
Comments
Post a Comment