Signal volume notes for process communication

Source: Internet
Author: User
Tags semaphore

Signal Volume Communication Module


semaphore function : The main role is to protect the street resources, that is, if the next year

Process requires a resource, the semaphore allows process a and process B to occupy
A certain amount of semaphore, each semaphore can only allow one process access, the semaphore is time
Limit, so that two processes have access to the same resource.

Classification:
Two value semaphore : The semaphore can only take 0 and 1, similar to the concept of mutual exclusion. When the resource is available
, the signal lights can be modified to become available. Two Mutual exclusion lock overview

The emphasis is on the process, which must be unlocked by the process after it has consumed the resources.

Count Semaphore : The value of the semaphore can be arbitrary non-negative. It's like I'm working in a factory,
Every time after work in the card, the first time the card is unsuccessful, you can not brush, in the back of the first let others

In the brush, and so other people brush well, you are in the brush, because everyone has a limited amount of time to swipe, can this

This avoids the problem of dead-lock lights.


Create Open

int Semget (key_t key, int nsems,int SEMFLG)


Key: Keys, the previous blog has mentioned, the first step to do.
Nsems: The number of sets of open or worn lights;
SEMFLG: Identity, similar to Message Queuing;

Operation
int semop (int semid, struct sembuf*sops, unsigned nsops)

Parameters:
Semid: The IP of the semaphore set
SOPs Operand, indicating what to manipulate
The number of elements of the array to which the nsops:sops points;

struct sembuf{
unsigned short sem_num; Gets the number of semaphores, the array below the table
Short Sem_op; Get or, release semaphore, 1 for release, 1 get
Short SEM_FLG; Flag, Ipc_nowait, returns an error immediately when the operand is not satisfied

Ipc_undo program whether normal or not normal to release the semaphore, to avoid deadlocks.


}

Signal volume notes for process communication

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.