![]() Once that process is complete, in process 2 the value of shared variable is changed to 4. We move back to process 1 and the value of shared variable becomes 6. Then we decrement the value of y and process 2 goes into sleep state. The integer y has the value of the shared variable initially which is unchanged, and is 5. Since the current processing is concurrent, the cpu does not wait and starts the processing of process 2. The value of x is then incremented, and it becomes 6 and post that the process goes into sleep state. We start with the execution of process 1, in which we declare a variable x which has initially the value of the shared variable which is 5. The resource here being the variable "shared" with value 5. ![]() What is our goal here? We want to achieve mutual exclusion, meaning that we want to prevent simultaneous access to a shared reource. We have 2 processes, that are concurrent and since we are talking about Process Synchronization, let's say they share a variable "shared" which has a value of 5. Now that you are familiar with these terms, we can move on to understanding the need of Semaphores with an example. This section is called the Critical Section. For any number of processes that are executing simultaneously, let's say all of them need to access a section of the code. Now this Process Synchronization is required for concurrent processes. Process Synchronization can be defined as the coordination between two process that have access to common materials such as a common section of code, resources or data etc.įor example: There may be some resource that is shared by 3 different processes, and none of the processes at a certain time can change the resource, since that might ruin the results of the other processes sharing the same resource. If not, let's quickly get comfortable with these terms above.Ĭoncurrent Processes are those processes that are executed simultaneously or parallely and might or might not be dependent on other processes. If you have read about Process Synchronization, you are aware of the critical section problem that arises for concurrent processes. ![]() We also cover the implementation of Semaphore with help of Producer-Consumer problem.In this article, we’ll discuss Semaphore, types of Semaphore in details with the help of exmaples.It is a concept in operating systems for the synchronization of concurrent processes. Semaphore is essentially a non negative integer that is used to solve the critical section problem by acting as a signal. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |