Re: repeat a function after fixed time period

From: Arjan van de Ven
Date: Thu Mar 24 2005 - 02:01:25 EST


On Wed, 2005-03-23 at 17:00 -0500, linux-os wrote:
> On Wed, 23 Mar 2005, Arjan van de Ven wrote:
>
> > On Wed, 2005-03-23 at 15:56 -0500, linux-os wrote:
> >>>> static void start_timer(void)
> >>>> {
> >>>> if(!atomic_read(&info->running))
> >>>> {
> >>>> atomic_inc(&info->running);
> >>>
> >>> same race.
> >>
> >> No such race at all.
> >
> > here there is one; you use add_timer() which isn't allowed on running
> > timers, only mod_timer() is. So yes there is a race.
> >
>
> Well add_timer() is only executed after the timer has expired
> or hasn't started yet so the "isn't allowed" is pretty broad.

See and the "hasn't started yet" isn't true due to the race. Assume 2
threads both hit the atomic_read() test at the same time, before they
each hit the inc. At some later point one of them will start the timer
and then the other will *again* add_timer on it.

> sequence. Will mod_timer() actually restart the timer???

yes


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/