[ECOS] problem in thread creation and scheduling
Fri Nov 26 11:18:00 GMT 2004
"Vijay Padiyar" <firstname.lastname@example.org> writes:
> Hi all
> We are having problems with thread creation in our application programs. So
> I made a subset of the code in question and put it in one file and ran it.
> I have a method 'Context::run()' inside a class 'Context'. I am creating two
> instances of class 'Context' and calling their 'run()' methods from the
> 'main()' function. The 'run()' method creates a thread and then starts it.
> After calling the method twice (which creates two separate threads), I call
> 'cyg_scheduler_start()' at the end of the program. However, the code inside
> the thread entry function doesn't seem to be executing! Particularly as I
> can't see the printf's inside the entry function on my terminal.
> Below is the code of my 'test.cpp' file:
> What could be going wrong? Between 'Thread created' and 'Thread started', we
> should see the printf's in the entry function. But we don't. All the data
> passed to the thread create function seems to be ok.
> However, when SIMPLE is defined and the program is run, the
> 'simple_function()' executes perfectly, and thread scheduler works just
The problem is that there are bugs in your code. After a brief
inspection I found the following:
1. The test and test2 objects are allocated as locals in main(). Since
your constructor does no initialization, the fields of these
objects will contain whatever random data was on the stack. When
main exits these objects will be destroyed and may be overwritten.
2. In most configurations main() runs in a thread so
cyg_scheduler_start() has already been called. Calling it again
will have undefined effects.
3. You call cyg_thread_set_priority() with a priority of (127 - priority/2).
eCos only supports priorities in the range 0..31.
I have no idea whether fixing these bugs will cause your program to
run, but it certainly won't run without it.
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts
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