This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Thread states


Paleologos Spanos wrote:
> 
>  Hi,I am working on eCos scheduler and I have a question concerning thread
> states.A preempted thread is in which state?the "Suspended"?Which is the
> state of a thread which has finished execution?thr "Exited"?

If a thread is timesliced, but would otherwise still have been runnable, it
will stay in the runnable state. The full states are described in this
extract from kernel/VERSION/include/thread.hxx:

        RUNNING    = 0,          // Thread is runnable or running
        SLEEPING   = 1,          // Thread is waiting for something to
happen
        COUNTSLEEP = 2,          // Sleep in counted manner
        SUSPENDED  = 4,          // Suspend count is non-zero
        CREATING   = 8,          // Thread is being created
        EXITED     = 16,         // Thread has exited

>   Actually I want to have a discrimination between preempted threads and
> threads which are just beginn execution. So,for example when there is a
> context switch I want to identify if this thread(next) is a preempted
> thread which will continue its execution or it is a new thread which is
> just beginn execution.Can I do this screening by checking the thread
> states?
>  If yes,which is the state for the threads in the 2 cases I mentioned?

Threads are created in the suspended state, which is why they must be
explicitly resumed before they start running. And you _can_ tell the
difference between a suspended thread and a running thread, although there
is no official API to do this (it's easy for you to add yourself though).

But once the thread is resumed, you won't be able to tell. But in that
case, why not just make the thread put something in a message box (or
something similar) when the thread starts?

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]