Problem when suspending a task.

Leon Pollak leonp at plris.com
Thu Jan 7 12:46:32 UTC 2010


On Thursday January 7 2010, Nick Thomas wrote:
> > -----Original Message-----
> > From: Leon Pollak [mailto:leonp at plris.com]
> > Sent: 07 January 2010 10:27
> > To: "Undisclosed.Recipients:"@plris.com
> > Cc: Nick Thomas
> > Subject: Re: Problem when suspending a task.
> >
> > On Thursday January 7 2010, Nick Thomas wrote:
> > > I presume that it is safe for task 'X' to suspend task 'Y' when 'Y'
> >
> > is
> >
> > > asleep, or waiting on a message Q.
> > > And possibly when waiting on a semaphore.
> > > So, is it possible to obtain the state of the task to be suspended,
> > > and if it's in one of those states then I can suspend it.
> > > I see that the task state is listed in the monitor 'task' command,
> >
> > but
> >
> > > this code is in RTEMS, and I can't see an obvious rtems_task_xxx API
> > > call to obtain this info. Is there one?
> >
> > Yes, this may be a way, although too complicated.
> >
> > May be you will consider the simpler decision: when you want to suspend
> > from task A task B set some flag variable in A, while B will test this
> > flag and suspend itself when not in a dangerous region.
> 
> OK, I understand that. And it seems like the best approach.
> But, in an effort to not disrupt code common with other non-rtems projects,
> I don't want to mess about with the tasks code too much. And there are lots
> of them.
> But, the OS API is abstracted, so if I can do it with my initial method
>  then it won't impact on other projects/products at all.
> I have seen the use of rtems_iterate_over_all_threads API, and this appears
> to work well enough for me.
> I just need to be sure that I can suspend the task when it is in a 'safe'
> state.
> 
> I have tested the two below, and that works. But, which of the others are
> 'safe'.
> I notice that a task could be in the 'READY' state quite a lot, is it safe
> to suspend the task when 'READY'?
NO!!!
The READY state means that the task is working (not waiting, etc.) now or was 
working at the moment it was interrupted by RTEMS (without going too deep into 
the task state options).
If you will suspend it in the ready state, it is very probable that it is just 
doing something critical.

About your method - note that the task you want to suspend may change its 
state while you are scanning and suspending it. You need to take special 
actions to safely do this operations...

BR
-- 
Leon



More information about the users mailing list