Integer semaphore and PV operation (computer operating system)

Source: Internet
Author: User

In the integer semaphore mechanism, the semaphore is defined as an shaping variable. In addition to the initial barbarian, only two standard atomic operations Wait (s) and signal (s) are accessible. They are usually referred to as P, v operations.

The description is as follows:

P Operation: s=s-1; if S is less than 0, the process goes into a wait state, otherwise it continues execution.

V Operation: s=s+1; if s>=0, a wait process in the wait queue is awakened.

The semaphore has its own physical meaning: when s>0, its value represents the number of classes of resources to be managed, and when s<0, its absolute values represent the number of processes waiting in the related queue.

Synchronization of processes

In general, the speed with which a process runs relative to another process is uncertain, that is, the process runs in an asynchronous environment, and each process advances at its own independent, unpredictable speed. However, the process of co-operation needs to coordinate their work at certain points, and when a process reaches these points, it will have to stop waiting for the operation to end unless another process has already done something. This is the synchronization of the process.

Mutex for process

In a multi-channel program system, each process can share various resources, but some resources can only be used by one process at a time, which is called critical resources.

The management principle of the critical zone: there is no time to enter, no empty then, limited waiting, let right wait.

When the process is mutually exclusive, the initial value of the semaphore is 1, while in the case of synchronization, the initial value of the semaphore is 0.

In solving the specific problems, in the face of various concurrent processes, we should first analyze which are mutually exclusive relationships, which are synchronous relationships, thereby determining which semaphores should be set and their initial value.

If the semaphore is set, each related process will execute P operation on it, and V operation on it, it is called a common semaphore. The common semaphore is used for mutual exclusion.

If the semaphore is set, only one process can perform p operations on it, and the other process can only perform v operations on it, it is called a private semaphore for that process. The amount of semaphores used for synchronization or resource allocation management is a private semaphore.

Integer semaphore and PV operation (computer operating system)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.