On Mon, 19 Mar 2007, matze wrote: > El Mon, Mar 19, 2007 at 06:04:38PM +0530 Daniel Rodrick ha dit: > > > On 3/19/07, Momchil Velikov <chill@xxxxxxxxx> wrote: > > >Daniel Rodrick wrote: > > >> I may be wrong, but from what I understand, the count passed in the > > >> semaphore initialization > > >> > > >> sema_init(sem, count); > > >> > > >> is the number of threads that are allowed to hold the semaphore > > >> simultaneously (no of threads that are allowed to enter their critical > > >> sections simultaneously). So can't a semaphore be actually held > > >> recursively? > > > > > >Semaphores are not "held". See below. > > > > > >> Also, the only difference I could find between a semaphore and mutes > > >> is that a mutex is a specail and most common form of semaphore where > > >> only one thread can get it at a time. Are there any other differences? > > > > > >The difference is that a semaphore has no owner. Neither semaphores nor > > >mutexes are a "special form" of the other - they are fundamentally > > >distinct mechanisms. > > > > > > > But I see mutexes implemented using semaphores only: > > > > #define __DECLARE_SEMAPHORE_GENERIC(name,count) \ > > struct semaphore name = __SEMAPHORE_INITIALIZER(name,count) > > > > #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1) > > #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0) > > that's the deprecated mutex API based on semaphores, AFAIK the one > described in http://lwn.net/Articles/167034/ should be used however, it's not clear that you can replace those (semaphore-based) "MUTEX"es with a real mutex, since mutexes aren't just semaphores with an initial count of 1, they have extra restrictions as we've already discussed here. if one wanted to go through the kernel tree and replace semaphores with mutexes, one would have to be *very* careful to do that only where the semantics made sense, no? rday -- ======================================================================== Robert P. J. Day Linux Consulting, Training and Annoying Kernel Pedantry Waterloo, Ontario, CANADA http://fsdev.net/wiki/index.php?title=Main_Page ======================================================================== -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ