[SunHELP] What is the purpose of SEMAPHORES???

Scott Jonathan sunhelp at sunhelp.org
Thu Dec 20 21:54:44 CST 2001


Semaphores are a type of IPC (InterProcess Communication). They help to get 
rid of race-conditions. They introduce a kind of hierarchy to locking 
resources for use. A simple example would be:

Process A wants to lock resource X and Y.
Process B wants to lock resource X and Y, as well.
Both resources are needed to get the job done, by A and B.
Process A locks X
Process B locks Y (someone decided to lock Y first, instead of X, the 
opposite of A)
Process A tries to lock Y, but gets blocked on the io call, and gets put to 
sleep holding the lock on X.
Process B tries to lock X, and ends up in the same condition; i.e. blocked 
on the io call for X and put to sleep. 

Neither process will now wake up, and resources X and Y are no longer 
available. Semaphores force programs to lock resources in an order, such 
that the above cannot happen. 

There are other situations you can use it in, but I cant think them up.;P 
Try looking up books on OS internals. There should be good info out there. 
I like the book "Linux Kernel Internals". My copy is quite old, but 
explains the basics well. There should be an updated version, to 2.2, I 
believe.

Good luck!

JS


>From: "Christopher Smiga" <csmiga at yahoo.com>
>Reply-To: sunhelp at sunhelp.org
>To: <sunhelp at sunhelp.org>
>Subject: [SunHELP] What is the purpose of SEMAPHORES???
>Date: Thu, 20 Dec 2001 22:43:40 -0500
>
>I was recently asked what a semaphore was in Solaris and I could not 
answer
>this question. Does anyone know what the purpose of this is. I believe 
they
>can be set up in "/etc/system", but that's all I know. Any information 
would
>be appreciated.
>
>Thank you,
>Christopher Smiga
>e-Mail: csmiga at yahoo.com
>
>----------------------------------------------------
>Sign Up for NetZero Platinum Today
>Only $9.95 per month!
>http://my.netzero.net/s/signup?r=platinum&refcd=PT97
>_______________________________________________
>SunHELP maillist  -  SunHELP at sunhelp.org
>http://www.sunhelp.org/mailman/listinfo/sunhelp




_________________________________________________________________
$B%$%s%?!<%M%C%H$r$V$i$V$i%7%g%C%T%s%0$9$k$J$i(BMSN $B%7%g%C%T%s%0$X(B 
http://shopping.msn.co.jp/



More information about the SunHELP mailing list