Bruce Eckel
Posts: 875
Nickname: beckel
Registered: Jun, 2003
|
|
Re: Threading Terminology
|
Posted: Oct 3, 2005 9:02 AM
|
|
Mutex is short for "mutual exclusion." It is a device that prevents more than one -- let's call it a "task" to be generic -- task at a time from accessing or modifying a shared resource.
So, if you're using a process, as you are referring to, that's generally managed at the OS level, and thus you need an OS-level mutex mechanism to prevent process-level tasks from interfering with each other.
And if you're working with threads, you need a thread-level mutex mechanism to prevent thread-level tasks from interfering with each other. In J2SE5, this includes the built-in locks that are part of every object and that you get with the synchronized keyword (that is, the original locks), and also the new java.util.concurrent.locks.Lock objects. (Locks are also called monitors).
Semaphores (also a new utility class in java.util.concurrent) allow you to keep a count of threads that have entered a particular critical section. Semaphores are generally used to create mutexes, not the other way around (the built-in lock in Java keeps track of how many acquisitions that a particular thread has acquired on a particular lock, and only releases the lock when the count goes to zero, so internally it looks like a semaphore).
|
|