lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] SemSignal gets called on a already signaled semaphore


From: Clive Wilson
Subject: Re: [lwip-users] SemSignal gets called on a already signaled semaphore
Date: Thu, 31 May 2007 23:24:02 +0100

At 10:20 31/05/2007, you wrote:
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

Jonathan,

As a clarification of the above example, is the intention for the mutex used by the semaphore pend to be the same as the one used by the semaphore post? I imagine not, otherwise the pend would wait on the condition variable with the mutex locked, therefore preventing a post from occurring...

Kind regards,

Clive Wilson





reply via email to

[Prev in Thread] Current Thread [Next in Thread]