30 likes | 169 Views
Why using mutex ?. The Critical-Section Problem Example: P1: repeat counter= counter +1; until false register1=counter; register1=register1+1; counter=register1;.
E N D
Why using mutex? The Critical-Section Problem Example: P1: repeat counter= counter +1; until false register1=counter; register1=register1+1; counter=register1; register1=counter; r1=5 register1=register1+1;r1=6 register2=counter; r2=5 register2=register2-1; r2=4 counter=register1;counter=6 counter=register2;counter=4 P2: repeat counter =counter -1; until false register2=counter; register2=register2-1; counter=register2; 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. program counter stack register address space memory file resources etc Thread: (lightweight process) a basic unit of CPU utilization, and consists of a program counter a register set stack space Share with 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.