Page 1 of 1

Semaphores

Posted: Mon Jun 13, 2011 11:23 am
by Dave_fr
Hi,

I'm banging my head against the wall because I can't get the binary semaphore to work. What I'm trying to do is the unlock a thread on receive of a shell command.
I tried to initialize a binary semaphore in the main(). Then, the tread is put on hold until the semaphore gets released. The semaphore is released in a shell's method.

Maybe I'm not looking where I should but I can't find any examples.

Can someone show me tell me how to initialize a binary semaphore and where ( in main() ?). Then how to perform the wait and release operation ?

Best regards,

David

Re: Semaphores

Posted: Mon Jun 13, 2011 11:49 am
by Giovanni
Hi,

It should be simple, you need to initialize the semaphore before its use, in main() is OK, just take care to initialize it as "taken". In you shell command you call chBSemSigna(), in the thread you use chBSemWait().

What problem are you experiencing?

Giovanni

Re: Semaphores

Posted: Mon Jun 13, 2011 11:57 am
by Dave_fr
I'm not sure I initialize de semaphore correctly.

Do you have to use " BSEMAPHORE_DECL ( ", "chBSemInit (" or both ?
Is possible you give me an example of a semphore initialization routine ?

Best regards,

Dave

Re: Semaphores

Posted: Mon Jun 13, 2011 12:40 pm
by Giovanni
The two forms are alternative.

Declaration:

BinarySemaphore my_bsem;

Initialization:

chBSemInit(&my_bsem, TRUE);

Giovanni

Re: Semaphores

Posted: Wed Jun 15, 2011 8:11 am
by Dave_fr
Changed the semaphore's name and it's now working great !
Sorry for that one Giovanni !