Critical Section Problem With a Simple Example.

Hello Friends, In this blog post(Critical Section Problem With a Simple Example) we are going to discuss the critical section problem which you would have read on the subject of the operating system probably.

A critical section is a part of a program that constantly tries to access the shared resources. These resources could be anything related to the computer like memory allocation, CPU, data structure, input and output devices.|Critical Section Problem With a Simple Example|

It has been observed that most of the users get confused with this critical section problem specially the students who study this in their academic syllabus.|Critical Section Problem With a Simple Example|

But you don’t have to worry at all as in this blog post we are going to explain this critical section problem as simple as possible with a simple example.

A critical section is a part of the program where only one process can execute at one time. And until it finishes the execution no other process can enter into the critical section. Till then the other process has to wait for their chance.

It is really hard for the operating system to allow and disallow any process to enter into the critical section. But still, it manages the best synchronization between the process and gets them executed into the critical section.

So we use this critical section problem to design a set of the protocol where the processes do get mashup into the race or deadlock condition.

And the main task or focus that we have through process synchronization is to solve the problem of critical section. And to do the same we have to satisfy few important condition which is given below:

Requirements for condition satisfaction :

mutual exclusion :

Our solution must provide mutual exclusion. As per the mutual exclusion if any process is executing in the critical section then no other process can enter into the critical section until the process execution is finished.

critical section mutual exclusion
critical section mutual exclusion

Progress :

If any process does not need the critical section for execution then it can not stop the other process to enter into the critical section.

Secondary:

Bounded waiting :

We should be capable to predetermine the waiting time of a process to enter into the critical section. It should happen that any process is waiting endlessly for entering into the critical section.

Architectural Neutrality

If our critical section problem solution is working fine at one architecture then it should work fine at the other architecture too.

Example: Critical Section Problem With a Simple Example

To understand this critical section problem better we make understand you with the help of a simple example:

Suppose we have a variable X and process A wants to read this and process B wants to write it at the same time.

But if happens then it might be a case then Process A get the wrong value to write and it would be the updated value that B will update through write operation.

So to solve this problem we first execute process B into the critical section and let it allow us to update or write the value of X. And till then process A will wait to read the value of X.

Once process B will finish the execution and update the value of X then process A will execute into the critical section and will read the value of X, and this time process B can not update the value of X as it can not enter into the critical section.

So doing this way process A will read the correct and updated value of X.|Critical Section Problem With a Simple Example|

Click here if you want to explore the Critical Section Problem In Hindi…

Conclusion:

So friends, In this blog post(Critical Section Problem With a Simple Example) we have gone through the critical section problem. In the problem of the critical section, one process executes into the critical section at a time, and till then no other process can enter into the critical section. And if any process does not need to enter into the critical section then it can not stop the other process to enter into the critical section. This critical section helps to retrieve the correct and updated value out of the program.

In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post about Critical Section Problem With a Simple Example.

Please feel free to give your important feedbacks in the comment section below.

Have a great time!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.