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
Semaphores
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Semaphores
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
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
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
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
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Semaphores
The two forms are alternative.
Declaration:
BinarySemaphore my_bsem;
Initialization:
chBSemInit(&my_bsem, TRUE);
Giovanni
Declaration:
BinarySemaphore my_bsem;
Initialization:
chBSemInit(&my_bsem, TRUE);
Giovanni
Re: Semaphores
Changed the semaphore's name and it's now working great !
Sorry for that one Giovanni !
Sorry for that one Giovanni !