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: Fw: infinite loop in cyg_thread_create() function


Hi

The problem with thread creation persists even if I provide a stack while
creating the thread. It still gets stuck in the same loop in
Cyg_thread::add_to_list() (thread.cxx).

As of now, I have declared a two-dimensional stack as follows:

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

#define NTHREADS 10
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL

static int stackPtr = 0;
static char stack[NTHREADS][STACK_SIZE];

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

and the cyg_thread_create() function is being called from inside a method
'run()' in a class 'Context' in our application file 'context.cpp':

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

void Context::run()
{
..
..
::cyg_thread_create(priority, (cyg_thread_entry_t
*)&contextStart,(cyg_addrword_t)this, tasknm, &stack[stackPtr], STACK_SIZE,
&handle1,
                                                &handle);
stackPtr++;
..
..
}
---------------------------------------------------------------

handle and handle1 are also defined in our header file 'context.h' under
'private:' in the definition of class 'Context:'

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

class Context
{
public:
    virtual void run();
..
..
private:
    #ifdef ECOS
    cyg_thread handle;
    cyg_handle_t handle1;
    #endif
..
..
}

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

'contextStart()', the function being pointed to in 'cyg_thread_create()', is
defined as follows in 'context.cpp'

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

void *contextStart(void *inst)
{
..
..
return 0;
}

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

I also put a 'printf' in method 'run()' to see if the memory areas of
consecutive thread stacks were overlapping. They are _not_. But yet the
problems persist. The stack space being allocated is surely more than what
is required, so no problems there.

What could be the problem? Could there be any other reasons behind this
behavior?

Regards

Vijay Padiyar


----- Original Message -----
From: "Bart Veer" <bartv@ecoscentric.com>
To: <vijaypadiyar@hotmail.com>
Cc: <ecos-discuss@sources.redhat.com>
Sent: Tuesday, November 02, 2004 4:15 AM
Subject: Re: [ECOS] Fw: infinite loop in cyg_thread_create() function


> >>>>> "Vijay" == Vijay Padiyar <vijaypadiyar@hotmail.com> writes:
>
>     Vijay> We are still facing the problem with thread creation that
>     Vijay> we faced earlier. We are calling cyg_thread_create() from
>     Vijay> inside a method inside a class:
>
>     Vijay> It's as follows:
>
>     <snip>
>
>     Vijay>     cyg_thread_create(priority, (cyg_thread_entry_t
>     Vijay> *)&contextStart,(cyg_addrword_t)this, tasknm, NULL, stackSize,
&handle1,
>     Vijay>                                                 &handle);
>
>     <snip>
>
>     Vijay> 'run()' is a method inside class 'Context'. Earlier we were
>     Vijay> defining a stack as 'static char stack[STACKSIZE]' just
>     Vijay> above the cyg_thread_create() call and passing '&stack[0]'
>     Vijay> as the argument. That was causing problems.
>
>     Vijay> But I read that passing 'NULL' will cause the
>     Vijay> cyg_thread_create() function to automatically allocate
>     Vijay> stack area on its own. But even with NULL, it doesn't seem
>     Vijay> to be working. It gets stuck in the same infinite loop in
>     Vijay> Cyg_thread::add_to_list() in thread.cxx, i.e. prev = NULL.
>
>     Vijay> How do we overcome this problem?
>
> You did not read that in the official documentation, see
> http://ecos.sourceware.org/docs-latest/ref/kernel-thread-create.html
> It is the application's responsibility to provide space for the thread
> stack, not the kernel's, because that way the kernel does not depend
> on dynamic memory allocation.
>
> That page in the documentation has an example which shows how to use
> cyg_thread_create() properly.
>
> Bart
>
> --
> Bart Veer                       eCos Configuration 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


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