Back To Course
Computer Science 305: Operating Systems8 chapters | 72 lessons
As a member, you'll also get unlimited access to over 75,000 lessons in math, English, science, history, and more. Plus, get practice tests, quizzes, and personalized coaching to help you succeed.
Try it risk-freeAlready registered? Login here for access
Process Synchronization is a way to coordinate processes that use shared data. It occurs in an operating system among cooperating processes. Cooperating processes are processes that share resources. While executing many concurrent processes, process synchronization helps to maintain shared data consistency and cooperating process execution. Processes have to be scheduled to ensure that concurrent access to shared data does not create inconsistencies. Data inconsistency can result in what is called a race condition. A race condition occurs when two or more operations are executed at the same time, not scheduled in the proper sequence, and not exited in the critical section correctly.
A critical section is a segment of code that can be accessed by only one signal process at a certain instance in time. This section consists of shared data resources that need to be accessed by other processes. The entry to the critical section is handled by the wait() function, represented as P(). The exit from a critical section is controlled by the signal() function, represented as V(). Only one process can be executed inside the critical section at a time. Other processes waiting to execute their critical sections have to wait until the current process finishes executing its critical section.
A critical section execution is handled by a semaphore. A semaphore is simply a variable that stores an integer value. This integer can be accessed by two operations: wait() and signal(). When a process enters the critical section, P(s) is invoked and the semaphore s is set to 1. After the process exits the critical section, s is re-initialized to 0. An example of how Process P is executed inside the critical section is shown below:
//Some Code
P(s);
//critical section(cs)
//exit from cs
V(s);
//remaining code
Semaphores can be classified into two types:
A binary semaphore can only take two values: 0 and 1. These semaphores are also known as mutex locks and are used to ensure mutual exclusion. If the mutex semaphore s is initialized to 0, then other processes can access the critical section. Otherwise, they have to wait for the process inside the critical section (where s=1) to finish its execution and s is set to 0.
A counting semaphore can take any integer value. This is helpful when there are multiple instances of a resource trying to access the critical section. For example, if there are 5 instances, then s is initialized to 5 and these 5 processes are granted access. When another process wants to access these resources, it has to wait until the signal function is called.
Let's take a couple moments to review what we've learned about process synchronization in operating systems.
Process synchronization coordinates processes trying to share resources and data. It helps keep the operating system from crashing. It occurs in an operating system among cooperating processes, which are processes that share resources. It looks very simple on the outside with a user interface, but on the inside, there is a lot going on every nanosecond. Process synchronization needs to be implemented to prevent data inconsistency among processes, process deadlocks, and prevent race conditions, which are when two or more operations are executed at the same time, not scheduled in the proper sequence and not exited in the critical section correctly.
A very popular solution to process synchronization is the implementation of the critical section, which is a segment of code that can be accessed by only one signal process at a certain instance in time. The critical section is a portion of code where processes sharing data are controlled using semaphores. Semaphores are integer variables that control when processes enter the critical section and the order these processes are executed. The two types of semaphores are: binary semaphore, also known as mutex locks, which can only take two values (0 and 1), and the counting semaphore, which can take any integer value.
The wait(), represented by p method, blocks processes from entering the critical section until the current process in the critical section completes and issues a signal(), represented by V method, which allows the next process in line to be executed.
To unlock this lesson you must be a Study.com Member.
Create your account
Already a member? Log In
BackAlready registered? Login here for access
Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.
To learn more, visit our Earning Credit Page
Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.
Back To Course
Computer Science 305: Operating Systems8 chapters | 72 lessons