From: Nick Garnett <nickg@ecoscentric.com>
To: "liu hua" <rongye_liu@hotmail.com>
Cc: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] Scheduler problem
Date: Mon, 04 Apr 2005 15:54:00 -0000 [thread overview]
Message-ID: <m3oecu5yir.fsf@xl5.calivar.com> (raw)
In-Reply-To: <BAY12-F145477A494A48C0D006527E8380@phx.gbl>
"liu hua" <rongye_liu@hotmail.com> writes:
> In the tewothreads example program, if I don't use cyg_thread_delay()
> in the 'simple_program' thread, or if use cyg_thread_delay(0), the two
> threads cannt be scheduled normally. The result is only one thread
> can run, and another thread is hung. thread program:
> 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 = 0+ (rand() % 0);
>
> /* note: printf() must be protected by a
> call to cyg_mutex_lock() */
> cyg_mutex_lock(&cliblock); {
> printf("Thread %d: and now a delay of %d clock ticks\n",
> message, delay);
> }
> cyg_mutex_unlock(&cliblock);
> cyg_thread_delay(0);
> }
> }
> Output result:
> Thread 0: and now a delay of 0 clock ticks
> Thread 0: and now a delay of 0 clock ticks
> Thread 0: and now a delay of 0 clock ticks
> Thread 0: and now a delay of 0 clock ticks
> ...
Thread 0 is higher priority that thread 1. Without the delays, thread
0 is always runnable and will always occupy the CPU. Thread 1 will
never get to execute.
>
> So, in my ecos application which have many thread have follow program:
> while (1)
> {
> ...
> }
If you write all your threads to just loop like this, then only the
highest priority thread will run. Just like you discovered above.
> If must I use cyg_thread_delay(delay) in it? ie:
> while (1)
> {
> ...
> cyg_thread_delay(delay);
> }
>
> If I must use cyg_thread_delay() in these threads, the performance of
> ecos will be a bad thing.
The general approach for writing multi-threaded applications is to
make threads wait for some event, do some processing, and then go back
to waiting. The event may be an interrupt, a timer, or a
synchronization action by some other thread.
--
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
next prev parent reply other threads:[~2005-04-04 15:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-01 8:38 liu hua
2005-04-02 1:52 ` John Newlin
2005-04-04 15:54 ` Nick Garnett [this message]
-- strict thread matches above, loose matches on Subject: below --
2003-11-19 4:20 [ECOS] scheduler problem Aravind B
2003-11-19 4:41 ` mohanlal jangir
2003-11-18 12:26 Aravind B
2003-11-18 12:36 ` Andrew Lunn
2003-10-13 12:14 [ECOS] Scheduler Problem James Yates
2003-10-13 11:54 James Yates
2003-10-13 12:01 ` Gary Thomas
2003-10-13 11:18 James Yates
2003-10-13 11:26 ` Iztok Zupet
2003-10-13 11:49 ` Gary Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3oecu5yir.fsf@xl5.calivar.com \
--to=nickg@ecoscentric.com \
--cc=ecos-discuss@sources.redhat.com \
--cc=rongye_liu@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).