public inbox for ecos-devel@sourceware.org
 help / color / mirror / Atom feed
* Unexpected exit from threads
@ 2006-11-23  8:43 David Luca
  2006-11-23  9:55 ` Nick Garnett
  0 siblings, 1 reply; 4+ messages in thread
From: David Luca @ 2006-11-23  8:43 UTC (permalink / raw)
  To: ecos-devel, ecos-discuss

Hello,

I tried the example found in twothreads.c, but renamed
the file to hello.cpp to compile it with g++.
I commented the printf calls and replaced with
lighting led functions. The code looks like:

void Led(int led)
{
	int j;
	for(j=0;j<100000;j++)
    	GPIO_clr(led);
	for(j=0;j<100000;j++)
    	GPIO_set(led);

}

/* now declare (and allocate space for) some kernel
objects,
   like the two threads we will use */
cyg_thread thread_s[2];		/* space for two thread
objects */

char stack[2][4096];		/* space for two 4K stacks */

/* now the handles for the threads */
cyg_handle_t simple_threadA, simple_threadB;

/* and now variables for the procedure which is the
thread */
cyg_thread_entry_t simple_program;

/* and now a mutex to protect calls to the C library
*/
cyg_mutex_t cliblock;

#ifdef __cplusplus
extern "C"{
#endif

void _impure_ptr()//required for C++ new operator
{
}
/* we install our own startup routine which sets up
threads */

void cyg_user_start(void)
{
//  printf("Entering twothreads' cyg_user_start()
function\n");

  cyg_mutex_init(&cliblock);

  cyg_thread_create(4, simple_program,
(cyg_addrword_t) USR_LED0, "Thread A", (void *)
stack[0], 4096,   &simple_threadA, &thread_s[0]);
  cyg_thread_create(4, simple_program,
(cyg_addrword_t) USR_LED1, "Thread B", (void *)
stack[1], 4096, &simple_threadB, &thread_s[1]);

  cyg_thread_resume(simple_threadA);
  cyg_thread_resume(simple_threadB);
}

#ifdef __cplusplus
};//extern "C"{
#endif
/* this is a simple program which runs in a thread */
void simple_program(cyg_addrword_t data)
{
  int message = (int) data;
  int delay;

//  printf("Beginning execution; thread data is %d\n",
message);

//  cyg_thread_delay(200);

  for (;;)
	{
    delay = 200 + (rand() % 50);

    /* note: printf() must be protected by a
       call to cyg_mutex_lock() */
    cyg_mutex_lock(&cliblock);
		{
		Led(message);	//light up/down led in 2 tasks
//      printf("Thread %d: and now a delay of %d clock
ticks\n",
//	     message, delay);
    	}
    cyg_mutex_unlock(&cliblock);
    cyg_thread_delay(delay);
  	}
}

When I run this example, I can see that each of the 2
leds are lit, then the threads exits without
continuing. Is there something wrong with the
scheduler? The platform used is based on Agilent
AAED2000 (Arm920). If you have any ideas, please
inform me. Thank you in advance,
David Luca.


 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unexpected exit from threads
  2006-11-23  8:43 Unexpected exit from threads David Luca
@ 2006-11-23  9:55 ` Nick Garnett
  2006-11-23 10:07   ` David Luca
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Garnett @ 2006-11-23  9:55 UTC (permalink / raw)
  To: David Luca; +Cc: ecos-devel, ecos-discuss

David Luca <davidluca3000@yahoo.com> writes:

> Hello,
> 
> I tried the example found in twothreads.c, but renamed
> the file to hello.cpp to compile it with g++.
> I commented the printf calls and replaced with
> lighting led functions. The code looks like:

What happens if you leave the printf()s in as well as the led
functions? Are you sure that the for loop are long enough for the led
changed to be visible? 

> 
> When I run this example, I can see that each of the 2
> leds are lit, then the threads exits without
> continuing.

It is unlikely that the threads are exiting...

> Is there something wrong with the
> scheduler?

...or that there is anything wrong with the scheduler.


-- 
Nick Garnett                                     eCos Kernel Architect
http://www.ecoscentric.com                The eCos and RedBoot experts

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unexpected exit from threads
  2006-11-23  9:55 ` Nick Garnett
@ 2006-11-23 10:07   ` David Luca
  2006-11-23 10:32     ` Nick Garnett
  0 siblings, 1 reply; 4+ messages in thread
From: David Luca @ 2006-11-23 10:07 UTC (permalink / raw)
  To: Nick Garnett, ecos-devel, ecos-discuss

Yes, the for loops are long enough for the leds to be
visible. I traced the cyg_thread_delay and after the
Cyg_Thread::unlock() call, nothing happens, the
execution goes to the main function.



--- Nick Garnett <nickg@ecoscentric.com> wrote:

> David Luca <davidluca3000@yahoo.com> writes:
> 
> > Hello,
> > 
> > I tried the example found in twothreads.c, but
> renamed
> > the file to hello.cpp to compile it with g++.
> > I commented the printf calls and replaced with
> > lighting led functions. The code looks like:
> 
> What happens if you leave the printf()s in as well
> as the led
> functions? Are you sure that the for loop are long
> enough for the led
> changed to be visible? 
> 
> > 
> > When I run this example, I can see that each of
> the 2
> > leds are lit, then the threads exits without
> > continuing.
> 
> It is unlikely that the threads are exiting...
> 
> > Is there something wrong with the
> > scheduler?
> 
> ...or that there is anything wrong with the
> scheduler.
> 
> 
> -- 
> Nick Garnett                                    
> eCos Kernel Architect
> http://www.ecoscentric.com                The eCos
> and RedBoot experts
> 
> 



 
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Unexpected exit from threads
  2006-11-23 10:07   ` David Luca
@ 2006-11-23 10:32     ` Nick Garnett
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Garnett @ 2006-11-23 10:32 UTC (permalink / raw)
  To: David Luca; +Cc: ecos-devel, ecos-discuss

David Luca <davidluca3000@yahoo.com> writes:

> Yes, the for loops are long enough for the leds to be
> visible.

It might be better to change the function so that each call toggles
the LED rather than turn it off and on.


> I traced the cyg_thread_delay and after the
> Cyg_Thread::unlock() call, nothing happens, the
> execution goes to the main function.

What do you mean by going to the main function? Which function is
that? In some configurations you might end up with a dummy main()
thread which will just exit, it won't have any effect on your program.

Can you still get this program running as it was originally intended,
with just the printf()s? If so, what then happens if you then add the
led functions? Try to work out what differs between the working
version and the non-working version.


-- 
Nick Garnett                                     eCos Kernel Architect
http://www.ecoscentric.com                The eCos and RedBoot experts

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-11-23 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-23  8:43 Unexpected exit from threads David Luca
2006-11-23  9:55 ` Nick Garnett
2006-11-23 10:07   ` David Luca
2006-11-23 10:32     ` Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).