Semaphores

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Dave_fr
Posts: 27
Joined: Thu Feb 17, 2011 11:26 pm

Semaphores

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Semaphores

Post 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
Dave_fr
Posts: 27
Joined: Thu Feb 17, 2011 11:26 pm

Re: Semaphores

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Semaphores

Post by Giovanni »

The two forms are alternative.

Declaration:

BinarySemaphore my_bsem;

Initialization:

chBSemInit(&my_bsem, TRUE);

Giovanni
Dave_fr
Posts: 27
Joined: Thu Feb 17, 2011 11:26 pm

Re: Semaphores

Post by Dave_fr »

Changed the semaphore's name and it's now working great !
Sorry for that one Giovanni !
Post Reply