Page 1 of 1
What is the best way to learn about semaphores?
Posted: Sat Oct 27, 2007 5:45 pm
by EliteLegend
I've been trying to get a grip on semaphores but for some reason unable to understand them fully.. Is there a place where I can get some explanation through some animations or videos or pictures?
Posted: Sun Oct 28, 2007 2:27 am
by os64dev
Dekker inventer of the P and V operations got his idea from train signal posts. So you might want to check those out.
Posted: Sun Oct 28, 2007 6:56 am
by Avarok
Semaphores... well... there's a problem with processors. They only do one thing at a time.
If two processors, A and B, use the same box... processor A puts a number in a box, it does some stuff, checks what's in the box and expects it to be there. But then just between checking and getting the stuff out of the box, process B changes it. Process A will keep on going with the wrong stuff.
So the smart programmer folk, they came up with this way to keep process B from
it all up.
They use a number to say who owns what's in the box. If a processor don't own what's in the box, it's not allowed to open the box and has to wait.
That's the strategy behind semaphores and mutexes, more or less, right?
Posted: Mon Oct 29, 2007 5:29 am
by JamesM
IIRC a mutex is just an abstract idea of a 'thing' that causes mutual exclusion to a resource. It is up to things like semaphores to concrete that abstraction.
The common idea of a 'mutex' is IIRC just a binary semaphore.
EDIT: google define: mutex pulls this up as the first result:
Google wrote:
Mutually-exclusive-access flag. Another name for a Semaphore.
Posted: Mon Oct 29, 2007 9:20 am
by Candy
A mutex offers the ability to take and replace it, where only one task will have the mutex at any time. Taking it when it isn't there amounts to blocking your thread until it is.
A semaphore offers the ability for a counter, which blocks your process when you try to take one off when it is 0. A mutex can be implemented based on a semaphore, where the value is set to 1 initially.
Posted: Wed Nov 07, 2007 12:10 pm
by EliteLegend
Thank you so much and sorry for the delay in replying... I was wondering on how to decide upon the number of semaphores that have to be used in your problem. Is there something to look for in a problem that helps us decide upon the usage of the total number of semaphores?
As I perceive, there should be one mandatory semaphore mutex (or whatever it is known as) to provide Mutual Exclusion. But what about the others?