[Gluster-devel] Is there a safe way to cancel a timer ?
Shyam
srangana at redhat.com
Mon Nov 10 14:36:07 UTC 2014
Hi Xavi,
I think you are referring to the problem as I see it, and have posted
here, http://review.gluster.org/#/c/6459/1/libglusterfs/src/timer.c
If so, there is nothing clean to handle the case in the code. Something
akin to returning a non-zero from the cancel and handling it by the
consumers is a possibility.
We need the fix mentioned above, and in addition to that some further
safety so that we free the pointers safely.
Shyam
On 11/10/2014 06:27 AM, Xavier Hernandez wrote:
> 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
> _______________________________________________
> Gluster-devel mailing list
> Gluster-devel at gluster.org
> http://supercolony.gluster.org/mailman/listinfo/gluster-devel
More information about the Gluster-devel
mailing list