mutex The Critical-Section Problem

advertisement
Why using mutex?
The Critical-Section Problem
Example: P1:
P2:
repeat
repeat
counter= counter +1;
until false
counter =counter -1;
until false
register1=counter;
r1=5
register1=register1+1;r1=6
register2=counter;
r2=5
register2=register2-1; r2=4
counter=register1;counter=6
register1=counter;
register2=counter;
register1=register1+1;
register2=register2-1;
counter=register1;
counter=register2;
counter=register2;counter=4
If one process is in its critical section, then no
other processes can be executing in their
critical section
Thread
Process: a program in execution. Thread: (lightweight process)
program counter
stack register
address space
memory
a basic unit of CPU utilization, and consists of
a program counter
a register set
stack space
file resources
Share with
etc
its code section,
data section
OS resources (files, etc)
Threads need less context switch time
Thread Programming
You may have to pass parameters to the function
when creating threads.
Try: man thr_create to get on line help on this.
Download