This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Fw: infinite loop in cyg_thread_create() function
- From: "Vijay Padiyar" <vijaypadiyar at hotmail dot com>
- To: "eCos Support" <ecos-discuss at sources dot redhat dot com>
- Date: Sat, 30 Oct 2004 10:10:52 +0530
- Subject: [ECOS] Fw: infinite loop in cyg_thread_create() function
Hi
We are still facing the problem with thread creation that we faced earlier.
We are calling cyg_thread_create() from inside a method inside a class:
It's as follows:
-------------------------------------------------------
void Context::run()
{
..
..
#ifdef ECOS
cyg_thread handle;
cyg_handle_t handle1;
cyg_thread_create(priority, (cyg_thread_entry_t
*)&contextStart,(cyg_addrword_t)this, tasknm, NULL, stackSize, &handle1,
&handle);
..
..
#endif
..
}
-------------------------------------------------------
'run()' is a method inside class 'Context'. Earlier we were defining a stack
as 'static char stack[STACKSIZE]' just above the cyg_thread_create() call
and passing '&stack[0]' as the argument. That was causing problems.
But I read that passing 'NULL' will cause the cyg_thread_create() function
to automatically allocate stack area on its own. But even with NULL, it
doesn't seem to be working. It gets stuck in the same infinite loop in
Cyg_thread::add_to_list() in thread.cxx, i.e. prev = NULL.
How do we overcome this problem?
Regards
Vijay
> Hi
>
> Just forwarding Aravind's reply to the mailing list.
>
> Regards
>
> Vijay
>
>
>
>
> > On Thu, 2004-10-28 at 19:55, Chandrashekhar Padiyar wrote:
> > > Hi Arvind
> > >
> > > You wrote about this problem on the eCos mailing list:
> > >
> >
>
> --------------------------------------------------------------------------
> ----
> > >
> > > > Thanks for ur kind reply
> > > > After debugging i found that problem is in following code fragment
in
> > > > file thread.cxx:
> > > >
> > > > Cyg_Thread::add_to_list( void )
> > > > - 127 {
> > > > 128 // Add thread to housekeeping list
> > > > 129 Cyg_Scheduler::lock();
> > > > 130
> > > > - 131 if( thread_list == 0 )
> > > > 132 list_next = this;
> > > > 133 else {prev != thread_list
> > > > 134 Cyg_Thread *prev = thread_list;
> > > > - 135 do {
> > > > - 136 if ( this == prev )
> > > > 137 break; // found it already!
> > > > - 138 prev = prev->list_next;
> > > > - 139 } while ( prev != thread_list );
> > > > - 140 if ( this != prev ) {
> > > > 141 // insert it in the list:
> > > > - 142 list_next = thread_list->list_next;
> > > > - 143 thread_list->list_next = this;
> > > > 144 }
> > > > 145 }
> > > >
> > > > the control is in the while loop forever as prev == thread_list (
line
> > > > 139 )ie prev has become NULL.
> > >
> >
>
> --------------------------------------------------------------------------
> ----
> > >
> > > Well we are facing the EXACT SAME problem now. Please tell us more
about
> how you solved it. We are calling the cyg_thread_create() function from a
> function inside a class. It gets stuck the second time in the same while()
> loop.
> > >
> > > Please tell us how exactly you modified the stack allocation.
> > >
> > > This is our function call:
> > >
> >
>
> --------------------------------------------------------------------------
> ----
> > >
> > > static char tskstack[STACK_SIZE]; //Stack size is 5632 bytes
> > >
> > > cyg_thread_create(10, (cyg_thread_entry_t
> *)&contextStart,(cyg_addrword_t)this,
> tasknm,&tskstack[STACK_SIZE],STACK_SIZE, &id1,
> > > &id);
> > >
> >
>
> --------------------------------------------------------------------------
> ----
> > >
> > > Please help us out here.
> > >
> > > Regards
> > >
> > > Vijay
> > >
> > i think u have created single dimension array for "space to store the
> thread data" and "for
> > pointer to the stack base" . Looking at what you sent you created one
> > thread with its stack stack[0] and the other thread with its stack
> > stack[1]. try creating a seperate array for each thread.
> >
> > regards
> > Aravind B
> >
> >
> >
>
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss