Hiya matey. One last beer before I hit the sack for the long day
tomorrow. Here's my tuppence. From a posixy point of view.
Rearranged the order to make it easier to explain.
Not sure what you mean by the use of the word static here. I *think*
you just mean mutex, see below.
This is a mechanism to provide 'mutual exclusion'. Often just called a
'lock'. If you acquire a mutex, you are guaranteed to be the only
person holding it. Typically you'll block until you can acquire it,
though there are various models. You would normally use a mutex to
protect some data:
int thingsToDo = 2; thingsDone = 0; // Must be kept consistent or
nuclear missiles will be launched
} // avoid WWIII
Anyone reading either var would have to grab the same aMutex.
The word has become diluted, though. These days people say 'mutex' to
mean some kind of lock in general, be it a traditional mutex, a rw
lock, a spinlock, a semaphore, etc...
This is usually like a mutex but with a count. You can think of it
like a pub on a Friday night. The first x people get in. After that,
it's a one-in, one-out policy. You normally decide x when you
create/init the semaphore.
Some models allow threads that don't own the sempahore to 'release' it.
(E.g. the bouncer spots a drunk stumbling out the fire exit, so lets
someone else in the front door.) Some people call these 'signal
sempahores' - they achieve roughly the same effect as mutex-condvar
I think there are two main definitions for this. The first is a
finite, single piece of code where someone (the compiler or the
hardware) guarantees that at most one thread will run in it
Today's definition amongst most I know is the Microsoft version - it's
basically a mutex.
The implementation and perf of each mechanism is very different,
You might also want to read up on:
- recursive locks
- rw locks
There's also lots of good lock-free stuff in this group.
Don't know why i did this by ng, will speak to you tues.