[Gluster-devel] Is there a safe way to cancel a timer ?

Xavier Hernandez xhernandez at datalab.es
Mon Nov 10 11:27:23 UTC 2014


Hi,

I'm having some problems when trying to cancel a timer. In current 
implementation it seems that it's not possible to know if a call to 
gf_timer_call_cancel() has really cancelled the timer or not. It means 
that it's possible that the callback will be called anyway.

This is problematic if the callback of the timer uses anything that can 
be modified after cancelling the timer.

For example:

void timer_callback(void * data)
{
     free(data);
}

void test()
{
     data = malloc(size);
     timer = gf_timer_call_after(ctx, delta, timer_callback, data);

     ...

     gf_timer_call_cancel(ctx, timer);
     free(data);
}

Obviously this is a simplified view, but the problem is there.

Wouldn't be necessary that gf_timer_call_cancel() returns 1 if it really 
cancelled the callback (i.e. it won't be called) and 0 if it will be 
called or it's being executed ?

Thanks,

Xavi


More information about the Gluster-devel mailing list