multiple tasks and timer setting, starting
Paolo Mantegazza
mantegazza at aero.polimi.it
Fri Jan 16 15:13:17 CET 2004
Herman Bruyninckx wrote:
> On Fri, 16 Jan 2004, Matteo Martegani wrote:
>
>
>> I'm coding a simple test case where different tasks are running on
>>the same machine. Any task can start the timer and set the mode, if the
>>timer isn't running yet (i.e. first task running starts the timer). The
>>obvious way to proceed is something in the lines of:
>>
>> if (!rt_is_hard_timer_running()){
>> rt_set_oneshot_mode();
>> start_rt_timer(0);
>> }
>>
>
> [...]
> The code above is prone to race conditions: what if it is called from
> two separate tasks, and one task is preempted at the check of the
> conditional?
>
> The generic design for this sort of "unique but shared" resources is
> that tasks do not do the actions themselves, but ask the "resource
> manager" to do it for them. The resource manager does the locking and
> synchronization of the access to the resource internally, guaranteeing
> race free execution.
> I think there are still many places within RTAI (and Linux!) where
> this "centralized resource management" design pattern should be
> introduced... (At least more explicitly than is done now.)
> Note that the "resource manager" need not be complex!
>
Well I think he had to do that as a way to avoid crashing an already
running hard timer. The race in this case is theoritically possible
UP/SMP but is difficult to have preemption in UP without the hard timer
running. In SMP it could but it is very very unlikely, so it will happen
:-). In any case it must be taken into account in a rewrite.
The problem I see is the one of braking any existing application
purposely issuing start_rt_timer, in a safe way and place, to reset it
and start anything anew.
If nobody says anything more I'll have a look, taking both suggestions
into account.
Paolo.
More information about the Rtai
mailing list