multiple tasks and timer setting, starting
Herman Bruyninckx
Herman.Bruyninckx at mech.kuleuven.ac.be
Fri Jan 16 09:48:03 CET 2004
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!
Herman
--
K.U.Leuven, Mechanical Engineering, Robotics Research Group
<http://people.mech.kuleuven.ac.be/~bruyninc> Tel: +32 16 322480
More information about the Rtai
mailing list