[ECOS] problem in thread creation and scheduling

Vijay Padiyar vijaypadiyar@hotmail.com
Thu Dec 2 13:07:00 GMT 2004

Hi Nick

Hey yeh you were right! Somehow we overlooked the vital fact that the
priority levels need to be between 0 and 31 for eCos!!! Actually we're
developing code to run on both VxWorks and eCos, so we have common variables
that are passed to the equivalent functions in all the files. Here, we
passed the 'priority' variable directly to 'cyg_thread_create()' without
realizing that its value ranges between 0 and 255.

I now added the following lines to my code:

#ifdef ECOS
priority = (int)(priority/8);

Thanks a lot for your help mate!!!



----- Original Message -----
From: "Nick Garnett" <nickg@ecoscentric.com>
To: "Vijay Padiyar" <vijaypadiyar@hotmail.com>
Cc: "eCos Support" <ecos-discuss@sources.redhat.com>
Sent: Friday, November 26, 2004 4:37 PM
Subject: Re: [ECOS] problem in thread creation and scheduling

> "Vijay Padiyar" <vijaypadiyar@hotmail.com> writes:
> > Hi all
> >
> > We are having problems with thread creation in our application programs.
> > I made a subset of the code in question and put it in one file and ran
> >
> > I have a method 'Context::run()' inside a class 'Context'. I am creating
> > instances of class 'Context' and calling their 'run()' methods from the
> > 'main()' function. The 'run()' method creates a thread and then starts
> >
> > After calling the method twice (which creates two separate threads), I
> > 'cyg_scheduler_start()' at the end of the program. However, the code
> > the thread entry function doesn't seem to be executing! Particularly as
> > 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
> > 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
> > fine!
> 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 -
>    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 mailing list