































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































-^ A computation typically consists of more than oneprocess or threads, and these processes frequentlyneed to communicate with one another. •^ Example: cat f1, f2, f3 | egrep OS^ – 2 processes are created^ – One process concatenates the files; the second file isblocked^ – Second process starts when the first process terminates.^ – The first process needs to communicate to the secondprocess before terminating.
shared double balance; Code for p^1
... balance = balance + amount;... Code for p^2 ... balance = balance - amount;...
balance+=amount
balance-=amount balance
-^ Situations when two are more processes (orthreads) are accessing a shared resource, and thefinal result depends on who run precisely when arecalled race conditions. •^ Race conditions can occur if two are moreprocesses are accessing a shared resource. •^ The part of the program where a shared resource isaccessed is called critical section
-^ We need a mechanism to prohibit multipleprocesses from accessing a shared resource at thesame time.
-^ Ensure that when a process is executing inits critical section, it cannot be preempted. •^ Disable all interrupts before entering a CS. •^ Enable all interrupts upon exiting the CS.
-^ Problems:^ 1.^ If a user forgets to enable interrupts???^ 2.^ Two or more CPUs??? •^ Interrupts could be disabled arbitrarilylong •^ Really only want to prevent p
-^ Attempt 2 (assume 2 processes)^ Process 1:
while (1) {^ while (turn != 0);^ CS^ turn = 1;^ other code^ } Process 2: while (1) {^ while (turn != 1);^ CS^ turn = 0;^ other code^ }
-^ Software solutions indicate the difficulty insolving mutual exclusion problem. •^ Need help from hardware. •^ Need to be able to look at a variable and set it upto some value without being interrupted.
y = read (x); x = value;
-^ Modern computing systems provide such aninstruction called
test-and-set (TS);
-^ TS(m)^ – Load contents of
m^ into a CPU register (with the condition code register contents set toreflect the value of
m ), and