AW: [En-Nut-Discussion] my mutex & semaphore implementation

Matthias Ringwald mringwal at inf.ethz.ch
Thu May 13 15:34:55 CEST 2004


Hi Oliver

thanks for reading the sources and giving feedback.


On 12.05.2004, at 08:59, Oliver Schulz wrote:
> But one question, in mutex implementation you used the terms Lock and
> Unlock, and in semaphore implementation the terms Wait and Post. Why
> that difference for the same kind of functions?

first, I used the posix mutex (man pthread_mutex_init) and
semaphore (man sem_init) implementation of my linux box as a reference.

I try to give better/more useful answer:
a thread can "lock" the one and only recursive mutex several times (and 
needs to
unlock the same number to free it)
but it "waits" to grab one of the resources guarded by the semaphore...

so, put it the other way: I provided both semaphore and mutex functions 
as
they provide different features altough a mutex can be seen as a 
semaphore
that is initialized with 1.

a semaphore can provide access to a number of restricted resources, 
where as
the feature of the mutex is, that it can be recursively locked by the 
same thread.
(this might be required sometimes)

ok. cool, I'll add it to the head branch soon.

cheers,
matthias




More information about the En-Nut-Discussion mailing list