Class Locker
Placement in the overall structure
- Module
- guard
- Base classes
- None
- Derived classes
- Guard
- Time of creation
- Task 3
- Files
locker.h
Description
The Locker class implements a lock that can be used to protect critical
sections. However, the variable only indicates whether the critical
section is free. Potentially necessary waiting, and protection for
counting functionality, must be implemented elsewhere.
Public methods
Locker ()
- Constructor that initializes the lock variable (free).
void enter ()
- This method must be called when entering the critical section.
void retne ()
- This method must be called when leaving the critical section.
bool avail ()
- Indicates whether the critical section is free.
Notes
-
The methods of the class are so short that it is best to
inline
them.
-
Doubled enter or retne calls (i.e. entering the critical
section from within the critical section or leaving it twice) are clear indications for
implementation bugs in the operating system. It may be
advisable to print an error message and halt the system in this case.