Matthias Weisser wrote:
Hi
After playing around with my echo server I saw a strange behavior of my
sys_sem_signal() implementation. I have implemented the semaphores as
binary mutexes. Now I see that one of the semaphores is created with a
initial count of 0 then signaled and then signaled again. Can this be
ignored as I expect or indicates it another bug in my port?
Semaphores and mutexes are not identical. Especially, as in this case,
when the semaphores are counting semaphores, not binary. But you can
abstract it using mutexes and condition variables, and a variable to
represent the semaphore count.
So waiting on a semaphore would mean:
lock mutex
while (count==0)
wait on condition variable
count--
unlock mutex
And posting a semaphore:
lock mutex
count++
signal condition variable
unlock mutex