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: Semaphore


"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




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