Software Locking (with hardware support)
Notes
- This is 6.5
- Mutex locks - mutual exclusion locks.
- Hardware locks are hard to use, especially in multi processor/core systems.
- So multiple software solutions are built on top.
- mutex locks have essentually two methods
- Acquire the lock
- Release the lock.
- Acquire should be written such that it is blocking until the process is safe to enter the critical section.
- In linux mutex is accomplished with
- The pthred_mutex routines.
-
int pthread_mutex_lock(pthread_mutex_t *mutex);
-
int pthread_mutex_trylock(pthread_mutex_t *mutex);
-
int pthread_mutex_unlock(pthread_mutex_t *mutex);
- These routines have a large range of behaviours
- We will only look at the process version, not the thread version.
- And this means a more complex setup stage.
- We need some shared memory, in this case we will use anonomous shared memory.
- Take a look at mutex.cpp.