Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
It makes sure that concurrent process access shared resources or data in a serialized way. If a process, says Pi, is executing in its critical section, then no other processes can be executing in their critical sections. Example: updating a DB or sending control signals to an IO device. Centralized Algorithm:
1. Process 1 asks the coordinator for permission to enter a critical region. Permission is granted 2. Process 2 then asks permission to enter the same critical region. The coordinator does not reply. 3. When process 1 exits the critical region, it tells the coordinator, which then replies to 2 [2] Advantages: Fair algorithm, grants in the order of requests The scheme is easy to implement Scheme can be used for general resource allocation
Critical Question: When there is no reply, does this mean that the coordinator is dead or just busy? Shortcomings Single point of failure. No fault tolerance Confusion between No-reply and permission denied Performance bottleneck of single coordinator in a large system
a. Two processes want to enter the same critical region. b. Process 0 has the lowest timestamp, so it wins. c. When process 0 is done, it sends an OK also, so 2 can now enter the critical region[2] Comparison of the Mutual Exclusion Algorithms:
Conclusion:
Thus we have successfully implemented Centralized Mutual Exclusion Algorithm. #include<iostream.h> #include<iomanip.h> #include<conio.h> int min(int ts[],int use[],int no,int m) { int i=0,u; int min=ts[use[0]]; u=use[0]; for(i=1;i<no;i++) { if((min>ts[use[i]])&&(m!=use[i])) { min=ts[use[i]]; u=use[i]; } } return u; }
cin>>n; for(i=0;i<n;i++) { cout<<"Enter timestamp of process "<<i+1<<endl; cin>>ts[i]; } cout<<"Enter no. of processes wanting to use the resource"<<endl; cin>>no; for(i=0;i<no;i++) { cout<<"Enter name of process"<<endl; cin>>use[i]; } for(i=0;i<no;i++) { cout<<"Process "<<use[i]<<" sends a request to the co-ordinator"<<endl; if(no==1) { cout<<use[no-1]<<" gets to access the resource"; } else { m=min(ts,use,no,p); p=m; cout<<"Process "<<m<<" gets to use the resource"<<endl;
cout<<"The remaining processes are waiting to use the resource"<<endl; cout<<endl; } getch(); } }
/*OUTPUT: Enter the no. of processes 5 Enter timestamp of process 1 2 Enter timestamp of process 2 4 Enter timestamp of process 3 1 Enter timestamp of process 4 3 Enter timestamp of process 5 6 Enter no. of processes wanting to use the resource 2 Enter name of process 2 Enter name of process
3 Process 2 sends a request to the co-ordinator Process 2 gets to use the resource The remaining processes are waiting to use the resource
Process 3 sends a request to the co-ordinator Process 3 gets to use the resource The remaining processes are waiting to use the resource */