Synchronization Part 2
Synchronization Part 2
problem
Issues of software based solution
• It involves Busy waiting
• It is limited to 2 processes.
TestAndSet
TestAndSet is a hardware solution to the synchronization problem. In TestAndSet, we have a shared lock variable
which can take either of the two values, 0 or 1.
0 Unlock 1 Lock
Before entering into the critical section, a process inquires about the lock. If it is locked, it keeps on waiting until
it becomes free and if it is not locked, it takes the lock and executes the critical section.
In TestAndSet, Mutual exclusion and progress are preserved but bounded waiting cannot be preserved.
• Create two semaphores: one to track the number of empty slots in the buffer
(emptyCount) and another to track the number of filled slots (fullCount).
• Create a mutex (bufferMutex) to control access to the buffer.
• Producer Code:
•{
• initializing_code;
•}
•}
11/19/2024 Nahida Nazir
• In an operating system, a monitor is only a class that
includes variable_declarations, condition_variables,
different procedures (functions), and an initializing_code
block for synchronizing processes.
• Shared Resource:
The shared resource is the data or resource that
multiple processes or threads need to access in a
mutually exclusive manner. Examples of shared
resources can include critical sections of code, global
variables, or any data structure that needs to be
accessed atomically