This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Semaphore
- From: Rafael Rodríguez Velilla <rrv at tid dot es>
- To: ecos <ecos-discuss at sources dot redhat dot com>
- Date: Wed, 14 Nov 2001 12:04:33 +0100
- Subject: Re: [ECOS] Semaphore
- Organization: Telefónica I+D
- References: <2439320011131441330140@2bsure.com>
"Chris C." wrote:
> Hi!
>
> Code:
> extern cyg_sem_t g_semInit;
>
> In cyg_user_start(),
> {
> thread_init();
> cyg_scheduler_start();
> cyg_semaphore_wait(&g_semInit);
> printf("wake up\n");
> }
>
> In about function, I called the thread_init to create a thread, init
> semaphore and resume it, this thread will call some functions and then call
> cyg_semaphore_post(&g_semInit). I found that the printf did not print the
> wake up message.
> Is there something wrong?
I think you shouldn't use such a call inside cyg_user_start, notice that
when you call cyg_scheduler_start cyg_user_start is abandoned and enters into
any thread.
When do you think that cyg_semaphore_wait is going to be executed? before
the thread? after the thread?... I'm not sure, I think it will never be
executed (I think that cyg_user_start never returns (it uses
HAL_THREAD_LOAD_CONTEXT).
You shouldn't expect the scheduler to return the control to cyg_user_start.
At the end of cyg_user_start, the scheduler is started automatically.
--
Rafael Rodríguez Velilla rrv@tid.es
Telefónica I+D http://www.tid.es
Telf: +34 - 91 337 4270