[ECOS] How to know if scheduler has started?

Grant Edwards grant.b.edwards@gmail.com
Thu Oct 31 16:25:00 GMT 2013

This question has come up many times in the past 10-12 years, but I've
never seen a real answer:

How do you tell if the scheduler has been started?

Specifically, how do you know when it's safe to attempt to lock a mutex?

Several people have suggested this snippet:

 scheduler_running = cyg_thread_self() != cyg_thread_idle_thread();

That seems to work when called from cyg_user_start() and from normal
threads, but it doesn't work when called from initialization code in 
a device driver.

So, I'll ask again:

how does one write code that knows to lock/unlock a mutex when called
from a normal user thread but not attempt the lock/unlock whcn called
from initialization code in cyg_user_start() or a device driver?

The function does not get called from ISR/DSR contexts: it is only
called during initialization (before the scheduler is started) and
from normal user threads.

OTOH, are you are allowed to lock/unlock mutexes from initialization
code?  Maybe I'm misremembering, but I thought that was forbidden?

Grant Edwards               grant.b.edwards        Yow! I was born in a
                                  at               Hostess Cupcake factory
                              gmail.com            before the sexual

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

More information about the Ecos-discuss mailing list