shanecordell

July 31, 2010

Knowledge sub-test system: PV operation and dispel doubts

Filed under: Uncategorized

Semaphore

Semaphore is the earliest process used to solve synchronization and mutual exclusion mechanism

Includes a variable called semaphore and its operations carried out by two of the original language.

1. Semaphore concept

1. Semaphore type definition

Each signal to be recorded for at least two messages: the value of the semaphore and wait for the process of the semaphore queue. Its type is defined as follows: (using class PASCAL language description)

semaphore = record

value: integer;

queue: ^ PCB;

end;

Which is the process control block PCB is created for each process operating system data structures.

s.value> = 0 ?? s.queue is empty;

s.value <0 ?? s.value s.queue the absolute value of the number of waiting processes;

2. PV primitives

On a semaphore variable can be two kinds of primitive operations: p operation and v operations, defined as follows: procedure p (var s: samephore);

(

s.value = s.value-1;

if (s.value <0) asleep (s.queue);

)

procedure v (var s: samephore);

(

s.value = s.value +1;

if (s.value < = 0) wakeup (s.queue);

)

Process which uses two criteria:

asleep (s.queue); do this, the process of PCB into the s.queue tail, the process into a wait state

wakeup (s.queue); will s.queue first process awakened into ready queue
s.value initial value is 1, the process can be used to achieve mutual exclusion.

operation and v p operation is not interrupted program segment, known as primitives. If the semaphore as a shared variable, pv operation for critical areas, multiple processes can run concurrently, the general method of using hardware guarantee. A signal can only be set once the initial value, since p can only be conducted on the operation or v operation.

This also can be seen that signal to the mechanism must have the public memory, can not be used for distributed operating system, which is its greatest weakness.

V of the original language of the main operations are:

(1) sem + 1;

(2) If the sum is greater than zero, then the process to continue;

(3) If the sum of the results is less than or equal to zero, the awakening of a block on the semaphore process, and then return to the original process to continue or switch to process scheduling.

Typical understanding of bias:

1 to 1,2 V steps to do the original language, Sem is not never greater than 0, it has been circulating the implementation process does not become a dead loop?

2, Sem greater than 0 it means there are critical resources available, why not wake up the process?

3, Sem less than 0 should be said that no critical resources available, why should wake up the process?

Questionable Points: 1, P operation on the sem by 1. P, V must be paired with the original language! Which will not cause an infinite loop. 2, Sem greater than 0 does that have critical resources available, but this time there is no process is blocked in the resources, that is not the process because they are not blocking these resources, so the process is not blocked, the natural do not wake up. 3, V is the essence of primitive operations: a process after you are finished using the critical resources, the release of critical resources to Sem plus 1, to notify the other of the process, this time if Sem <0, that there are processes blocked in such resources, So wake up from the block queue of a process to “pass” such resources. For example, there are two certain types of resources, the three processes A, B, C, D to use such resources, the beginning Sem = 2, when A entered, Sem = 1, when B entered Sem = 0, show that such resources just run out, when C comes in Sem =- 1, that a process is blocked, D to enter, Sem =- 2. A run out of resources such as, for V operation, Sem =- 1, the release of these resources, then Sem <0, that there are processes blocked in such resources, so wake up one.

To further deepen the understanding, then the introduction of two questions: 4, are mutually exclusive semaphore if so, should set the semaphore Sen = 1, but when there are five processes to access it, the final list in the amount of the signal will be 4 years were waiting, that is, S =- 4, then the first process performed at 1 V operation to S to release the resources, the next one should be able to perform, but the wake of the process operation in the implementation of P due to S <0, also or execution can not, how is this going on? 5, Sem process of waiting for the absolute value of said number, at the same time that critical resources, which in the end how the story? Questionable Points: 4, when a process blocked when it has performed a P operation and the place cards in the critical region. When the wake-up immediately when it entered the critical area of its own, does not need to perform the P operation, and when finished the critical section implementation process, the implementation of the V operation. 5, when the semaphore Sem less than 0, its absolute value such that system resources requested by the process blocked number. S is greater than 0, said the number of available critical resources. Note that expressed in different situations different meaning. When equal to 0, that is just exhausted.

????:

Java And JavaScript Report

Dell's real AMBITION

Mp4 converter to avi

Convert .avi to .wmv

XHTML Basic questions and answers - for beginners

From “Made in China” to “Created in China”

Simple Network And Internet

free converter mp4 to 3gp

2006 China's first three-dimensional DIGITAL modeling contest grand start

ARTICLES about Search Or Lookup Tools

AMD INTEL on EU antitrust penalties comment

Beijing Matsushita employee dissatisfaction compensation for loss of containment of the company

About Groovy and Grails

Qualcomm CEO: WiMax 3G will compete in the face of setbacks

Swf format

Comments »

The URI to TrackBack this entry is: http://shanecordellus.blogsome.com/2010/07/31/knowledge-sub-test-system-pv-operation-and-dispel-doubts/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers