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: Question about scheduler & sleep


On Friday 16 August 2002 16:07, jyl087@netscape.net wrote:
> In my application, I have a section of code which is surrounded by
> cyg_scheduler_lock/unlock. Now, within that section, I call
> cyg_thread_delay(128). My intention is to have a 128 tick pause,
> without allowing context switching.
>
> When I step through the code with GDB, I find that the code does
> pause, however, when it returns from the cyg_thread_delay, the
> thread is still in the SLEEPING state. It actually continues to
> execute until the cyg_scheduler_unlock() is called, at which point
> it goes into a deep sleep...
>
> In summary:
>
>   cyg_scheduler_lock();      RUNNING
>     ...
>     cyg_thread_delay(128);   SLEEPING
>     ...                      SLEEPING, but executing code!
>   cyg_scheduler_unlock();    SLEEPING, and really dead
>
> Question... is this a bug in the thread mechanism, or is my
> use of the library wrong?
>
> Thanks
> /Jim

Does it really make sense to disable context switching and to go
into a sleep?  After all, when you go to sleep, you are releasing the
CPU to run other threads.  If no other thread is available to run,
the idle thread ought to run.

An uglier but portable way to disable context switching and to do a
128 tick delay would be something like this:

------------------------
cyg_tick_count_t start_tick;

cyg_scheduler_lock();
start_tick = cyg_current_time();
while (cyg_current_time() < start_tick + 128)
{
  /* do nothing except heat up CPU */
}
cyg_scheduler_unlock();

------------------------

I am sure there are more elegant ways to do it taking advantage
of your chip's low power mode but the above should do in a pinch.

-Rich

-- 
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]