Cleaning up after timer_delete

Rémi Denis-Courmont remi@remlab.net
Sat Jul 25 17:31:00 GMT 2009


Le samedi 25 juillet 2009 20:11:34 Carlos O'Donell, vous avez écrit :
> > I'm wondering how to use interval timers from a library such that I can
> > safely clean up data after the timer is disarmed.
>
> Disarm the timer from the event thread, which AFAICT should assure you
> that no other events are possible, only one event may be executing at
> a given moment (overruns are reported via timer_getoverrun()).

That's not what I understand from POSIX neither from the glibc source code. 
If I'm reading glibc source code right, it's just waiting for SIGTIMER. When 
it occurs, it takes a global lock, creates a thread, releases the lock. It is 
nowhere waiting for the created thread to finish before it tries to create a 
new one. So in my understanding, especially with a very short interval, the 
timer function could be running in more than one thread at a time for the same 
timer ID.

I guess timer_getoverrun() returns the number of SIGTIMER raises that were not 
delivered due to scheduling constraints.

> e.g.
> * In foo_stop set the stop flag.
> * In foo_timer check the flag, if set delete the timer, clear the
> flag, and return.
> * In foo_stop continue waiting for flag to clear, and once clear
> deallocate the resources.


-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the Libc-help mailing list