Problem when suspending a task.

Joel Sherrill joel.sherrill at OARcorp.com
Thu Jan 7 12:55:23 UTC 2010


On 01/07/2010 06:26 AM, 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.
>    
The POSIX threads API has cleanup push and pop.

In general terms, each thread has "safe" areas to suspend or
delete it.  Those are the same no matter what OS is underneath.
I am just rambling but if you defined something in your application
OS abstraction layer to say "ok to XXX me" and the task would enter
and exit safe states as it worked.
> 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.
>    
Remember, there is NO NO NO protection when using that helper. :)
> 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'?
>
>    
Not if it has a mutex locked, just turned on a motor for a train
going down a track and won't be able to turn it off.   It might be
safe and it might not.
> #define STATES_READY                           0x00000
> #define STATES_DORMANT                         0x00001
> #define STATES_SUSPENDED                       0x00002
> #define STATES_TRANSIENT                       0x00004
> #define STATES_DELAYING                        0x00008 /* OK */
> #define STATES_WAITING_FOR_TIME                0x00010
> #define STATES_WAITING_FOR_BUFFER              0x00020
> #define STATES_WAITING_FOR_SEGMENT             0x00040
> #define STATES_WAITING_FOR_MESSAGE             0x00080 /* OK */
> #define STATES_WAITING_FOR_EVENT               0x00100
> #define STATES_WAITING_FOR_SEMAPHORE           0x00200
> #define STATES_WAITING_FOR_MUTEX               0x00400
> #define STATES_WAITING_FOR_CONDITION_VARIABLE  0x00800
> #define STATES_WAITING_FOR_JOIN_AT_EXIT        0x01000
> #define STATES_WAITING_FOR_RPC_REPLY           0x02000
> #define STATES_WAITING_FOR_PERIOD              0x04000
> #define STATES_WAITING_FOR_SIGNAL              0x08000
>
>    
>> BR
>> --
>> Leon
>> --
>>              Dr.Leon M.Pollak
>>                  Director
>>         PLR Information Systems Ltd.
>> Tel.:+972-98657670  |  POB 8130, H'Aomanut 9,
>> Fax.:+972-98657621  |  Poleg Industrial Zone,
>> Mob.:+972-544739246 |  Netanya, 42160, Israel.
>>      
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-users
>    




More information about the users mailing list