[MUD-Dev] Semaphores, Mutices, fd_sets

Jeff Kesselman jeffk at tenetwork.com
Sat Apr 26 12:25:38 CEST 1997


At 09:08 AM 4/26/97 PST8PDT, you wrote:
>I've seen the words 'Semaphore' and 'Mutex' thrown about in RGMA lately. 
>But I have no idea what they are. Would anyone be able to help me out?

Mutex -- Short Hand for Mutally Exclusive.  Sometimes Mutex is used as
shorthand for Mutex Semaphore, the most common type of Semaphore.

Sempahore--  The term goes all the way back to semaphore flags, which were
physical cloth flags the navy would wave at each other to coordinate
actions.  In computer science, a sempahore is a flag used to control access
to a loimited resource.  

For instance, if you have a number of threads that communciate using a
commonly accesible variable, you may have periods in each peice of code
where you expect it to remain the same after you have read it.  The simple
solution is to use "Critical Sections" where you turn off multi-threading
entirely during that period, but thsi often has a bad impact on program
performance and is generally discouraged.  

Instead, you set up a mutually-exclusive sempahore.  When a thread wants
access to the variable, it requests to control (or 'lock') the sempahore.
If noone elaready has control, the call return and the code has control
until it gives it up ('releases'). If someone else already has control, the
thread automaticly goes to sleep (pauses) until it CAN get control of the
sempahore, at which point it wakes up and returns.  Naturally if you have
mroe then 2 processes this implies the need for a "sleep queue" so they
each get woekn up in turn.
>
>Also, an fd_set holds FD_SETSIZE file descriptors. Is it true that a 
>theroretically infinite number of FDs can be opened by the server, 

Depends on the operating system, but often not. Most commonly fds are
handled by a fixed size table in the process structure in the underlying OS.

JK




More information about the mud-dev-archive mailing list