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]
Other format: [Raw text]

Re: cyg_thread_resume question


On Thu, Jul 03, 2003 at 11:24:01AM +0530, mohanlal jangir wrote:
> I have a question regarding following lines from eCos reference guide:
> "cyg_thread_suspend can be used to increment the suspend counter, and
> cyg_thread_resume decrements it. The scheduler will never run a thread with
> a non-zero suspend counter"
> 
> Does it mean that resuming a thread without varify if it is sleeping or not
> can lead the thread to be non-runnable? For example a thread X is in ready
> state but not getting executed because some higher priority thread Y is
> running. Now thread Y calls cyg_thread_resume(X). This will decrement the
> suspend counter of thread X, which was already zero. Will the thread X now
> ever run?

Here is the code that does the real work.....

Cyg_Thread::resume()
{
    CYG_REPORT_FUNCTION();
 
    CYG_INSTRUMENT_THREAD(RESUME,this,Cyg_Scheduler::current_thread);
 
    // Prevent preemption
    Cyg_Scheduler::lock();
 
    // If we are about to zero the count, clear the state bit and
    // reschedule the thread if possible.
    
    if( suspend_count == 1 )
    {
        suspend_count = 0;
 
        CYG_ASSERT( (state & SUSPENDED) != 0, "SUSPENDED bit not set" );
        
        // Set the state
        state &= ~SUSPENDED;
 
        // Return thread to scheduler if runnable
        if( state == RUNNING )
            Cyg_Scheduler::scheduler.add_thread(this);
    }
    else
        if( suspend_count > 0 )
            suspend_count--;
    // else ignore attempt to resume
 
    // Unlock the scheduler and maybe switch threads
    Cyg_Scheduler::unlock();
 
    CYG_REPORT_RETURN();
}

ie if the count is 0, it will not go negative.

        Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


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