Synchronization mechanisms Flashcards
what is the critical section problem
each process has a critical section that is mutually exclusive - if one process is in its critical section, no other process may be in its critical section
how to design a protocol to solve this
Name the three requirements for solutions to critical section problem
mutual exclusion
progress
bounded waiting
what is meant by mutual exclusion
if process a is in its critical section, no other process can be in its critical section
what is meant by progress (requirement for solution to crit section problem)
any process wanting to enter its critical section should be allowed to compete to enter and we should be able to make the decision in a reasonable amount of time
what is meant by bounded waiting
there exists a limit on the number of times that other processses are allowed to enter their critical sections after a process has made a request to enter its critical section
basically if a process requests to enter its crit section, there should be a limit to the number of other processes that will exectute their crit sections before it - i.e. should be granted access to its critical section in a reasonable amount of time
Name and explain some hardware solutions to synchronization
test-and-set() - combines the actions of testing and setting a variable into a single machine instruction that cannot be interrupted
compare-and-swap() - swaps the value of a variable only if equal to the expected value
do not satisfy bounded waiting
Name some software solutions
mutex lock
semaphores
Different types of semaphores
binary
counting
what are monitors
high level abstraction that provides a convenient and effective mechanism for process synchronization - class in which all data is private and onlt one method within any given monitor is active at a time
monitor methods may only access the shared data within the monitor and nay data passed to them as parameters.. i.e. they cannot access any data external to the monitor
what are condition variables
condition x;
x.wait() - suspend process until x.signal() is called
there is not much detail about this?
Signaling pattern with semaphores
See physical notes
A1 before B1
Thread A
a1()
sem.signal()
Thread B
sem.wait()
b1
Rendezvous pattern
See physical notes
a1 before b2 and b1 before a2
Thread a
a1()
aSem.signal()
bSem.wait()
a2()
Thread b
b1()
bSem.signal()
aSem.wait()
b2()
Barriers
Lecture video - physical notes