trying to clarify the variety of semaphores and mutexes

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

 



  i'd like to clarify the different varieties of semaphores and
mutexes and if someone can fill in the blanks, i'd appreciate it.

  as i read it, first there were general semaphores, defined in the
include/asm-*/semaphore.h files.  these are general counting
semaphores, and can be used in places only where contending tasks
could sleep, so they're not suitable for, say, interrupt handlers.
(they can't be used in interrupt context.)

  in those same semaphore.h files, there are also special cases to
declare binary semaphores using DECLARE_MUTEX and init_MUTEX.
however, while these advertise the word "mutex", they are simply a
general semaphore with possible values of 0 and 1 (a binary
semaphore), so they have all the same power and restrictions of a
normal semaphore, there's just a convenient syntax to declare the
restricted binary case.

  and, finally, there is the newer actual "mutex", described in
Documentation/mutex-design.txt, which has simpler semantics and some
restrictions that semaphores don't.  is this about right so far?

  so, in terms of cleaning up mutexes in the source tree, it's
possible to replace a "binary" semaphore with an actual mutex, as long
as that binary semaphore is being used in such a way that all of the
restrictions of mutexes are satisfied (and, certainly, not all of them
are).

  also, it's unfortunate that the semaphore.h files declare binary
semaphores using macros that contain the word "mutex" since that just
*begs* to be confused with actual mutexes.

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


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux